Search in sources :

Example 6 with Content

use of io.swagger.v3.oas.annotations.media.Content 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);
                }
            }
        }
    }
}
Also used : Example(io.swagger.v3.oas.models.examples.Example) Schema(io.swagger.v3.oas.models.media.Schema) RefUtils.isAnExternalRefFormat(io.swagger.v3.parser.util.RefUtils.isAnExternalRefFormat) RefUtils.computeRefFormat(io.swagger.v3.parser.util.RefUtils.computeRefFormat) RefFormat(io.swagger.v3.parser.models.RefFormat) MediaType(io.swagger.v3.oas.models.media.MediaType)

Example 7 with Content

use of io.swagger.v3.oas.annotations.media.Content 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);
        }
    }
}
Also used : Header(io.swagger.v3.oas.models.headers.Header) Schema(io.swagger.v3.oas.models.media.Schema) Example(io.swagger.v3.oas.models.examples.Example) MediaType(io.swagger.v3.oas.models.media.MediaType) Link(io.swagger.v3.oas.models.links.Link)

Example 8 with Content

use of io.swagger.v3.oas.annotations.media.Content 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"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Example 9 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.

the class ParameterProcessorTest method testProcessParameters_BodyParameter.

@Test
public void testProcessParameters_BodyParameter(@Injectable final Schema bodyParamSchema) throws Exception {
    expectedModelProcessorCreation();
    RequestBody bodyParameter = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(bodyParamSchema)));
    expectModelProcessorInvoked(bodyParamSchema);
    new RequestBodyProcessor(cache, openAPI).processRequestBody(bodyParameter);
    new FullVerifications() {

        {
        }
    };
}
Also used : Content(io.swagger.v3.oas.models.media.Content) MediaType(io.swagger.v3.oas.models.media.MediaType) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 10 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.

the class InlineModelResolverTest method testInlineMapResponseWithObjectSchema.

@Test
public void testInlineMapResponseWithObjectSchema() throws Exception {
    OpenAPI openAPI = new OpenAPI();
    Schema schema = new Schema();
    schema.setAdditionalProperties(new ObjectSchema().addProperties("name", new StringSchema()));
    schema.addExtension("x-ext", "ext-prop");
    ApiResponse apiResponse = new ApiResponse().description("it works!").content(new Content().addMediaType("*/*", new MediaType().schema(schema)));
    apiResponse.addExtension("x-foo", "bar");
    ApiResponses apiResponses = new ApiResponses().addApiResponse("200", apiResponse);
    openAPI.path("/foo/baz", new PathItem().get(new Operation().responses(apiResponses)));
    new InlineModelResolver().flatten(openAPI);
    ApiResponse response = openAPI.getPaths().get("/foo/baz").getGet().getResponses().get("200");
    Schema property = response.getContent().get("*/*").getSchema();
    assertTrue(property.getAdditionalProperties() != null);
    assertEquals(1, property.getExtensions().size());
    assertEquals("ext-prop", property.getExtensions().get("x-ext"));
    assertTrue(openAPI.getComponents().getSchemas().size() == 1);
    Schema inline = openAPI.getComponents().getSchemas().get("inline_response_map200");
    assertTrue(inline instanceof Schema);
    assertNotNull(inline.getProperties().get("name"));
    assertTrue(inline.getProperties().get("name") instanceof StringSchema);
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Content(io.swagger.v3.oas.models.media.Content) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) Test(org.testng.annotations.Test)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)121 Test (org.testng.annotations.Test)120 MediaType (io.swagger.v3.oas.models.media.MediaType)70 Schema (io.swagger.v3.oas.models.media.Schema)70 Operation (io.swagger.v3.oas.annotations.Operation)65 Content (io.swagger.v3.oas.models.media.Content)64 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)62 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)57 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 Operation (io.swagger.v3.oas.models.Operation)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)42 PathItem (io.swagger.v3.oas.models.PathItem)41 ArrayList (java.util.ArrayList)41 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)40 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)37 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)37 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)33