Search in sources :

Example 21 with OpenAPIResolver

use of io.swagger.v3.parser.OpenAPIResolver 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"));
}
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) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 22 with OpenAPIResolver

use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testOperationBodyParameterRemoteRefs.

@Test
public void testOperationBodyParameterRemoteRefs() {
    final Schema schema = new Schema();
    final OpenAPI swagger = new OpenAPI();
    swagger.path("/fun", new PathItem().get(new Operation().parameters(Arrays.asList(new Parameter().$ref("#/components/parameters/SampleParameter")))));
    swagger.path("/times", new PathItem().get(new Operation().parameters(Arrays.asList(new Parameter().$ref("#/components/parameters/SampleParameter")))));
    swagger.components(new Components().addParameters("SampleParameter", new Parameter().name("skip").schema(schema)));
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters();
    assertEquals(params.size(), 1);
    final Parameter param = params.get(0);
    assertEquals(param.getName(), "skip");
}
Also used : Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) 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) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

OpenAPIResolver (io.swagger.v3.parser.OpenAPIResolver)21 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Test (org.testng.annotations.Test)16 StringSchema (io.swagger.v3.oas.models.media.StringSchema)15 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)14 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)13 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)13 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)13 Schema (io.swagger.v3.oas.models.media.Schema)13 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)10 Operation (io.swagger.v3.oas.models.Operation)8 PathItem (io.swagger.v3.oas.models.PathItem)8 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)8 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)8 Components (io.swagger.v3.oas.models.Components)7 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)7 Parameter (io.swagger.v3.oas.models.parameters.Parameter)6 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)6 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5