use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class XmlModelTest method deserializeModel.
@Test(description = "it should deserialize a model")
public void deserializeModel() throws IOException {
final String yaml = "---\n" + "type: \"object\"\n" + "properties:\n" + " id:\n" + " type: \"string\"\n" + " xml:\n" + " attribute: true\n" + " name:\n" + " type: \"string\"\n" + " xml:\n" + " name: \"renamed\"\n" + " list:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + " wrappedList:\n" + " type: \"array\"\n" + " xml:\n" + " name: \"wrappedListItems\"\n" + " wrapped: true\n" + " items:\n" + " type: \"string\"\n" + " forcedElement:\n" + " type: \"array\"\n" + " items:\n" + " type: \"string\"\n" + "xml:\n" + " name: \"rootName\"";
final Schema model = Yaml.mapper().readValue(yaml, Schema.class);
final Schema wrappedList = (Schema) model.getProperties().get("wrappedList");
assertNotNull(wrappedList);
assertNotNull(wrappedList.getXml());
assertEquals(wrappedList.getXml().getName(), "wrappedListItems");
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testSerializePetstore.
@Test
public void testSerializePetstore() throws Exception {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1.yaml");
final OpenAPI swagger = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
assertEquals(swagger.getInfo().getLicense().getIdentifier(), "test");
SerializationMatchers.assertEqualsToYaml31(swagger, "openapi: 3.1.0\n" + "info:\n" + " title: Swagger Petstore\n" + " license:\n" + " name: MIT\n" + " identifier: test\n" + " version: 1.0.0\n" + "servers:\n" + "- url: http://petstore.swagger.io/v1\n" + "paths:\n" + " /pets:\n" + " get:\n" + " tags:\n" + " - pets\n" + " summary: List all pets\n" + " operationId: listPets\n" + " parameters:\n" + " - name: limit\n" + " in: query\n" + " description: How many items to return at one time (max 100)\n" + " required: false\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " \"200\":\n" + " description: An paged array of pets\n" + " headers:\n" + " x-next:\n" + " description: A link to the next page of responses\n" + " schema:\n" + " type: string\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pets'\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + " post:\n" + " tags:\n" + " - pets\n" + " summary: Create a pet\n" + " operationId: createPets\n" + " responses:\n" + " \"201\":\n" + " description: Null response\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + " /pets/{petId}:\n" + " get:\n" + " tags:\n" + " - pets\n" + " summary: Info for a specific pet\n" + " operationId: showPetById\n" + " parameters:\n" + " - name: petId\n" + " in: path\n" + " description: The id of the pet to retrieve\n" + " required: true\n" + " schema:\n" + " type: string\n" + " responses:\n" + " \"200\":\n" + " description: Expected response to a valid request\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pets'\n" + " default:\n" + " description: unexpected error\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Error'\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " required:\n" + " - id\n" + " - name\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type:\n" + " - string\n" + " - integer\n" + " tag:\n" + " type: string\n" + " Pets:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Pet'\n" + " Error:\n" + " required:\n" + " - code\n" + " - message\n" + " properties:\n" + " code:\n" + " type: integer\n" + " format: int32\n" + " message:\n" + " type: string\n" + "webhooks:\n" + " newPet:\n" + " post:\n" + " requestBody:\n" + " description: Information about a new pet in the system\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Pet'\n" + " responses:\n" + " \"200\":\n" + " description: Return a 200 status to indicate that the data was received\n" + " successfully");
SerializationMatchers.assertEqualsToJson31(swagger, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"info\" : {\n" + " \"title\" : \"Swagger Petstore\",\n" + " \"license\" : {\n" + " \"name\" : \"MIT\",\n" + " \"identifier\" : \"test\"\n" + " },\n" + " \"version\" : \"1.0.0\"\n" + " },\n" + " \"servers\" : [ {\n" + " \"url\" : \"http://petstore.swagger.io/v1\"\n" + " } ],\n" + " \"paths\" : {\n" + " \"/pets\" : {\n" + " \"get\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"List all pets\",\n" + " \"operationId\" : \"listPets\",\n" + " \"parameters\" : [ {\n" + " \"name\" : \"limit\",\n" + " \"in\" : \"query\",\n" + " \"description\" : \"How many items to return at one time (max 100)\",\n" + " \"required\" : false,\n" + " \"schema\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " }\n" + " } ],\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"An paged array of pets\",\n" + " \"headers\" : {\n" + " \"x-next\" : {\n" + " \"description\" : \"A link to the next page of responses\",\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pets\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"post\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"Create a pet\",\n" + " \"operationId\" : \"createPets\",\n" + " \"responses\" : {\n" + " \"201\" : {\n" + " \"description\" : \"Null response\"\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"/pets/{petId}\" : {\n" + " \"get\" : {\n" + " \"tags\" : [ \"pets\" ],\n" + " \"summary\" : \"Info for a specific pet\",\n" + " \"operationId\" : \"showPetById\",\n" + " \"parameters\" : [ {\n" + " \"name\" : \"petId\",\n" + " \"in\" : \"path\",\n" + " \"description\" : \"The id of the pet to retrieve\",\n" + " \"required\" : true,\n" + " \"schema\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " } ],\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"Expected response to a valid request\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pets\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"default\" : {\n" + " \"description\" : \"unexpected error\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Error\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"Pet\" : {\n" + " \"required\" : [ \"id\", \"name\" ],\n" + " \"properties\" : {\n" + " \"id\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int64\"\n" + " },\n" + " \"name\" : {\n" + " \"type\" : [\"string\", \"integer\"]\n" + " },\n" + " \"tag\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " },\n" + " \"Pets\" : {\n" + " \"type\" : \"array\",\n" + " \"items\" : {\n" + " \"$ref\" : \"#/components/schemas/Pet\"\n" + " }\n" + " },\n" + " \"Error\" : {\n" + " \"required\" : [ \"code\", \"message\" ],\n" + " \"properties\" : {\n" + " \"code\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " },\n" + " \"message\" : {\n" + " \"type\" : \"string\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"webhooks\" : {\n" + " \"newPet\" : {\n" + " \"post\" : {\n" + " \"requestBody\" : {\n" + " \"description\" : \"Information about a new pet in the system\",\n" + " \"content\" : {\n" + " \"application/json\" : {\n" + " \"schema\" : {\n" + " \"$ref\" : \"#/components/schemas/Pet\"\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"responses\" : {\n" + " \"200\" : {\n" + " \"description\" : \"Return a 200 status to indicate that the data was received successfully\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ParameterSerializationTest method testIssue1765.
@Test(description = "should serialize correctly typed numeric enums")
public void testIssue1765() throws Exception {
String yaml = "openapi: '3.0.1'\n" + "paths:\n" + " /test:\n" + " get:\n" + " parameters:\n" + " - name: \"days\"\n" + " in: \"path\"\n" + " required: true\n" + " schema:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - 3\n" + " - 4\n" + " - 5\n" + " responses:\n" + " default:\n" + " description: great";
OpenAPI swagger = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(swagger, yaml);
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeHeaderParameter.
@Test(description = "it should it should serialize a HeaderParameter")
public void serializeHeaderParameter() {
final Parameter p = new HeaderParameter().schema(new StringSchema());
final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"string\"}}";
SerializationMatchers.assertEqualsToJson(p, json);
final String yaml = "---\n" + "in: \"header\"\n" + "schema:\n" + " type: \"string\"";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeBodyParameterToYaml.
@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
final Schema model = new Schema().title("Cat").addProperties("name", new StringSchema());
final RequestBody p = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(model)));
final String yaml = "---\n" + "content:\n" + " '*/*':\n" + " schema:\n" + " title: Cat\n" + " properties:\n" + " name:\n" + " type: string";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Aggregations