use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class ParameterProcessor method processParameter.
public void processParameter(Parameter parameter) {
String $ref = parameter.get$ref();
if ($ref != null) {
RefFormat refFormat = computeRefFormat(parameter.get$ref());
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalParameter($ref, refFormat);
if (newRef != null) {
parameter.set$ref(newRef);
}
}
}
if (parameter.getSchema() != null) {
schemaProcessor.processSchema(parameter.getSchema());
}
if (parameter.getExamples() != null) {
Map<String, Example> examples = parameter.getExamples();
for (String exampleName : examples.keySet()) {
final Example example = examples.get(exampleName);
exampleProcessor.processExample(example);
}
}
Schema schema = null;
if (parameter.getContent() != null) {
Map<String, MediaType> content = parameter.getContent();
for (String mediaName : content.keySet()) {
MediaType mediaType = content.get(mediaName);
if (mediaType.getSchema() != null) {
schema = mediaType.getSchema();
if (schema != null) {
schemaProcessor.processSchema(schema);
}
}
}
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class ResponseProcessor method processResponse.
public void processResponse(ApiResponse response) {
if (response.get$ref() != null) {
processReferenceResponse(response);
}
Schema schema = null;
if (response.getContent() != null) {
Map<String, MediaType> content = response.getContent();
for (String mediaName : content.keySet()) {
MediaType mediaType = content.get(mediaName);
if (mediaType.getSchema() != null) {
schema = mediaType.getSchema();
if (schema != null) {
schemaProcessor.processSchema(schema);
}
}
if (mediaType.getExamples() != null) {
for (Example ex : mediaType.getExamples().values()) {
exampleProcessor.processExample(ex);
}
}
}
}
if (response.getHeaders() != null) {
Map<String, Header> headers = response.getHeaders();
for (String headerName : headers.keySet()) {
Header header = headers.get(headerName);
headerProcessor.processHeader(header);
}
}
if (response.getLinks() != null) {
Map<String, Link> links = response.getLinks();
for (String linkName : links.keySet()) {
Link link = links.get(linkName);
linkProcessor.processLink(link);
}
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class SchemaProcessor method processReferenceSchema.
private void processReferenceSchema(Schema schema) {
/* if this is a URL or relative ref:
1) we need to load it into memory.
2) shove it into the #/components/schemas
3) update the RefModel to point to its location in #/components/schemas
*/
RefFormat refFormat = computeRefFormat(schema.get$ref());
String $ref = schema.get$ref();
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
if (newRef != null) {
schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
}
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method referringSpecWithoutComponentsTag.
@Test
public void referringSpecWithoutComponentsTag() throws Exception {
ParseOptions resolve = new ParseOptions();
resolve.setResolveFully(true);
final OpenAPI openAPI = new OpenAPIV3Parser().read("./ref-without-component/a.yaml", null, resolve);
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
Assert.assertEquals("Example value", schemas.get("CustomerType").getExample());
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testResponseRemoteRefs.
private void testResponseRemoteRefs(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref(remoteRef))))))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
final Schema ref = response.getContent().get("*/*").getSchema();
assertEquals(ref.get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Aggregations