use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue5.
@Test(description = "Tags are missing in the converted spec")
public void testIssue5() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(PET_STORE_JSON);
// Global Tags
List<Tag> tags = oas.getTags();
assertNotNull(tags);
assertEquals(PET_TAG, tags.get(0).getName());
// Operation Tag
Operation petPut = oas.getPaths().get(PET_PATH).getPut();
assertNotNull(petPut.getTags());
assertEquals(PET_TAG, petPut.getTags().get(0));
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method componentsResolver.
@Test
public void componentsResolver() throws Exception {
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
final JsonNode rootNode = mapper.readTree(pathFile.getBytes());
final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
final SwaggerParseResult result = deserializer.deserialize(rootNode);
Assert.assertNotNull(result);
final OpenAPI openAPI = result.getOpenAPI();
Assert.assertNotNull(openAPI);
assertEquals(new OpenAPIResolver(openAPI, new ArrayList<>(), null).resolve(), openAPI);
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
// internal url schema
Schema pet = schemas.get("Pet");
Schema category = (Schema) pet.getProperties().get("category");
assertEquals(category.get$ref(), "#/components/schemas/Category");
// remote url schema
Schema user = (Schema) pet.getProperties().get("user");
assertEquals(user.get$ref(), "#/components/schemas/User");
// ArraySchema items
ArraySchema tagsProperty = (ArraySchema) pet.getProperties().get("tags");
assertEquals(tagsProperty.getItems().get$ref(), "#/components/schemas/ExampleSchema");
assertEquals(tagsProperty.getType(), "array");
Assert.assertNotNull(openAPI.getComponents().getSchemas().get("ExampleSchema"));
// Schema not
assertEquals(schemas.get("OrderRef").getNot().get$ref(), "#/components/schemas/Category");
// Schema additionalProperties
assertTrue(schemas.get("OrderRef").getAdditionalProperties() instanceof Schema);
Schema additionalProperties = (Schema) schemas.get("OrderRef").getAdditionalProperties();
assertEquals(additionalProperties.get$ref(), "#/components/schemas/User");
// AllOfSchema
ComposedSchema extended = (ComposedSchema) schemas.get("ExtendedErrorModel");
Schema root = (Schema) extended.getAllOf().get(0).getProperties().get("rootCause");
assertEquals(root.get$ref(), "#/components/schemas/Category");
Map<String, ApiResponse> responses = openAPI.getComponents().getResponses();
// internal response headers
ApiResponse illegalInput = responses.get("IllegalInput");
assertEquals(illegalInput.getHeaders().get("X-Ref-Limit-Limit").get$ref(), "#/components/headers/X-Rate-Limit-Reset");
// internal response links
assertEquals(illegalInput.getLinks().get("address").get$ref(), "#/components/links/unsubscribe");
// internal url response schema
MediaType generalError = responses.get("GeneralError").getContent().get("application/json");
assertEquals(generalError.getSchema().get$ref(), "#/components/schemas/ExtendedErrorModel");
Map<String, RequestBody> requestBodies = openAPI.getComponents().getRequestBodies();
// internal url requestBody schema
RequestBody requestBody1 = requestBodies.get("requestBody1");
MediaType xmlMedia = requestBody1.getContent().get("application/json");
assertEquals(xmlMedia.getSchema().get$ref(), "#/components/schemas/Pet");
// internal url requestBody ArraySchema
RequestBody requestBody2 = requestBodies.get("requestBody2");
MediaType jsonMedia = requestBody2.getContent().get("application/json");
ArraySchema items = (ArraySchema) jsonMedia.getSchema();
assertEquals(items.getItems().get$ref(), "#/components/schemas/User");
// internal request body
assertEquals("#/components/requestBodies/requestBody2", requestBodies.get("requestBody3").get$ref());
// remote request body url
assertEquals(requestBodies.get("reference").get$ref(), "#/components/requestBodies/remote_requestBody");
Map<String, Parameter> parameters = openAPI.getComponents().getParameters();
// remote url parameter
assertEquals(parameters.get("remoteParameter").get$ref(), "#/components/parameters/parameter");
// internal Schema Parameter
assertEquals(parameters.get("newParam").getSchema().get$ref(), "#/components/schemas/Tag");
// parameter examples
assertEquals(parameters.get("contentParameter").getExamples().get("cat"), openAPI.getComponents().getExamples().get("cat"));
// parameter content schema
assertEquals(parameters.get("contentParameter").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ExtendedErrorModel");
// internal Schema header
Map<String, Header> headers = openAPI.getComponents().getHeaders();
// header remote schema ref
assertEquals(headers.get("X-Rate-Limit-Remaining").getSchema().get$ref(), "#/components/schemas/User");
// header examples
assertEquals(headers.get("X-Rate-Limit-Reset").getExamples().get("headerExample").get$ref(), "#/components/examples/dog");
// remote header ref
assertEquals(headers.get("X-Ref-Limit-Limit").get$ref(), "#/components/headers/X-Rate-Limit-Reset");
// header content
assertEquals(headers.get("X-Rate-Limit-Reset").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ExtendedErrorModel");
Map<String, Example> examples = openAPI.getComponents().getExamples();
// internal url example
Example frogExample = examples.get("frog");
assertEquals(frogExample.get$ref(), "#/components/examples/cat");
// remote example url
assertEquals(examples.get("referenceCat").get$ref(), "#/components/examples/example");
// internal url securityScheme
SecurityScheme scheme = openAPI.getComponents().getSecuritySchemes().get("reference");
assertEquals(scheme.getType(), SecurityScheme.Type.APIKEY);
SecurityScheme remoteScheme = openAPI.getComponents().getSecuritySchemes().get("remote_reference");
assertEquals(remoteScheme.getType(), SecurityScheme.Type.OAUTH2);
Map<String, Link> links = openAPI.getComponents().getLinks();
// internal link
assertEquals(openAPI.getComponents().getLinks().get("referenced").get$ref(), "#/components/links/unsubscribe");
// remote ref link
assertEquals(openAPI.getComponents().getLinks().get("subscribe").get$ref(), "#/components/links/link");
Map<String, Callback> callbacks = openAPI.getComponents().getCallbacks();
// internal callback reference
assertEquals(callbacks.get("referenced").get$ref(), "#/components/callbacks/failed");
// callback pathItem -> operation ->requestBody
assertEquals(callbacks.get("heartbeat").get("$request.query.heartbeat-url").getPost().getRequestBody().get$ref(), "#/components/requestBodies/requestBody3");
// remote callback ref
assertEquals(callbacks.get("remoteCallback").get$ref(), "#/components/callbacks/callback");
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue450.
@Test
public void testIssue450() {
String desc = "An array of Pets";
String xTag = "x-my-tag";
String xVal = "An extension tag";
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 0.0.0\n" + " title: Simple API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + "components:\n" + " schemas:\n" + " PetArray:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Pet'\n" + " description: An array of Pets\n" + " x-my-tag: An extension tag\n" + " Pet:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
assertNotNull(result.getOpenAPI());
final OpenAPI openAPI = result.getOpenAPI();
Schema petArray = openAPI.getComponents().getSchemas().get("PetArray");
assertNotNull(petArray);
assertTrue(petArray instanceof ArraySchema);
assertEquals(petArray.getDescription(), desc);
assertNotNull(petArray.getExtensions());
assertNotNull(petArray.getExtensions().get(xTag));
assertEquals(petArray.getExtensions().get(xTag), xVal);
}
use of io.swagger.v3.jaxrs2.resources.model.Tag 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.jaxrs2.resources.model.Tag in project swagger-core by swagger-api.
the class SchemaSerializationTest method serializeRefSchema3_1.
@Test
public void serializeRefSchema3_1() {
OpenAPI openAPI = new OpenAPI().components(new Components().addSchemas("Pet", new Schema().addProperties("id", new Schema().type("integer")).addProperties("name", new Schema().type("string")).addProperties("tag", new Schema().type("string"))).addSchemas("AnotherPet", new Schema().title("Another Pet").description("Another Pet for petstore referencing Pet schema").$ref("#/components/schemas/Pet").addProperties("category", new Schema().type("string")).addProperties("photoUrl", new Schema().type("string"))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id: {}\n" + " name: {}\n" + " tag: {}\n" + " AnotherPet:\n" + " title: Another Pet\n" + " properties:\n" + " category: {}\n" + " photoUrl: {}\n" + " description: Another Pet for petstore referencing Pet schema\n" + " $ref: '#/components/schemas/Pet'");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id:\n" + " type: integer\n" + " name:\n" + " type: string\n" + " tag:\n" + " type: string\n" + " AnotherPet:\n" + " $ref: '#/components/schemas/Pet'");
}
Aggregations