use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testOperationBodyparamRemoteRefs.
private void testOperationBodyparamRemoteRefs(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.path("/fun", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref(remoteRef)))))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final RequestBody param = swagger.getPaths().get("/fun").getGet().getRequestBody();
final Schema ref = param.getContent().get("*/*").getSchema();
assertEquals(ref.get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);
assertNotNull(result);
assertTrue(result.getMessages().size() == 2);
OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Schema petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArraySchema petArrayModel = (ArraySchema) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
Schema refProp = petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/components/schemas/Pet");
assertNull(petArrayModel.getProperties());
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertPath.
private void assertPath(Class<?> testEndpointClass, Method expectedEndpointMethod, PathItem actualPath, HashMap<String, Class<?>> typeArguments) {
Operation actualOperation = actualPath.getPost();
assertEquals("Unexpected tag in the OpenAPI spec", Collections.singletonList(testEndpointClass.getSimpleName()), actualOperation.getTags());
assertTrue(String.format("Unexpected OpenAPI operation id: does not contain the endpoint name of the class '%s'", testEndpointClass.getSimpleName()), actualOperation.getOperationId().contains(getEndpointName(testEndpointClass)));
assertTrue(String.format("Unexpected OpenAPI operation id: does not contain the name of the endpoint method '%s'", expectedEndpointMethod.getName()), actualOperation.getOperationId().contains(expectedEndpointMethod.getName()));
if (expectedEndpointMethod.getParameterCount() > 0) {
Schema requestSchema = extractSchema(actualOperation.getRequestBody().getContent());
Type[] genericParameterTypes = expectedEndpointMethod.getGenericParameterTypes();
Class<?>[] parameterTypes = new Class<?>[genericParameterTypes.length];
List<HashMap<String, Class<?>>> parameterTypeArguments = new ArrayList<>();
for (int i = 0; i < genericParameterTypes.length; i++) {
parameterTypes[i] = applyTypeArguments(genericParameterTypes[i], typeArguments);
parameterTypeArguments.add(i, extractTypeArguments(genericParameterTypes[i], typeArguments));
}
assertRequestSchema(requestSchema, parameterTypes, parameterTypeArguments, expectedEndpointMethod.getParameters());
} else {
assertNull(String.format("No request body should be present in path schema for endpoint method with no parameters, method: '%s'", expectedEndpointMethod), actualOperation.getRequestBody());
}
ApiResponses responses = actualOperation.getResponses();
assertEquals("Every operation is expected to have a single '200' response", 1, responses.size());
ApiResponse apiResponse = responses.get("200");
assertNotNull("Every operation is expected to have a single '200' response", apiResponse);
Type genericReturnType = expectedEndpointMethod.getGenericReturnType();
Class<?> returnType = applyTypeArguments(genericReturnType, typeArguments);
Class<?> mappedType = new EndpointTransferMapper().getTransferType(returnType);
if (mappedType != null) {
returnType = mappedType;
}
if (returnType != void.class) {
assertSchema(extractSchema(apiResponse.getContent()), returnType, extractTypeArguments(genericReturnType, typeArguments));
} else {
assertNull(String.format("No response is expected to be present for void method '%s'", expectedEndpointMethod), apiResponse.getContent());
}
assertNotNull("Non-anonymous endpoint method should have a security data defined for it in the schema", actualOperation.getSecurity());
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-core by swagger-api.
the class PatternAndSchemaPropertiesTest method testPatternAndSchemaProperties.
@Test
public void testPatternAndSchemaProperties() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
Schema model = context.resolve(new AnnotatedType(AnnotatedPet.class));
assertEquals(((Schema) model.getPatternProperties().get("what.*ever")).getFormat(), "int32");
assertEquals(((Schema) model.getPatternProperties().get("it.*takes")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherCategory")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherInteger")).getFormat(), "int32");
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "AnnotatedPet:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " description: Annotated Pet\n" + " nullable: true\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag");
context.getDefinedModels().values().forEach(s -> new OpenAPISchema2JsonSchema().process(s));
SerializationMatchers.assertEqualsToYaml31(context.getDefinedModels(), "AnnotatedPet:\n" + " type:\n" + " - object\n" + " - \"null\"\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " patternProperties:\n" + " what.*ever:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " it.*takes:\n" + " $ref: '#/components/schemas/Category'\n" + " description: Annotated Pet\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag\n");
}
use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-core by swagger-api.
the class AnnotationsUtils method getTags.
public static Optional<Set<Tag>> getTags(io.swagger.v3.oas.annotations.tags.Tag[] tags, boolean skipOnlyName) {
if (tags == null) {
return Optional.empty();
}
Set<Tag> tagsList = new LinkedHashSet<>();
for (io.swagger.v3.oas.annotations.tags.Tag tag : tags) {
if (StringUtils.isBlank(tag.name())) {
continue;
}
if (skipOnlyName && StringUtils.isBlank(tag.description()) && StringUtils.isBlank(tag.externalDocs().description()) && StringUtils.isBlank(tag.externalDocs().url())) {
continue;
}
Tag tagObject = new Tag();
if (StringUtils.isNotBlank(tag.description())) {
tagObject.setDescription(tag.description());
}
tagObject.setName(tag.name());
getExternalDocumentation(tag.externalDocs()).ifPresent(tagObject::setExternalDocs);
if (tag.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(tag.extensions());
if (extensions != null) {
extensions.forEach(tagObject::addExtension);
}
}
tagsList.add(tagObject);
}
if (tagsList.isEmpty()) {
return Optional.empty();
}
return Optional.of(tagsList);
}
Aggregations