Search in sources :

Example 31 with Schema

use of io.swagger.v3.oas.annotations.media.Schema 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 32 with Schema

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

the class SchemaProcessorTest method testProcessRefSchema_ExternalRef.

@Test
public void testProcessRefSchema_ExternalRef() throws Exception {
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    final String newRef = "bar";
    setupPropertyAndExternalRefProcessors();
    new StrictExpectations() {

        {
            externalRefProcessor.processRefToExternalSchema(ref, RefFormat.URL);
            times = 1;
            result = newRef;
        }
    };
    Schema refSchema = new Schema().$ref(ref);
    new SchemaProcessor(cache, openAPI).processSchema(refSchema);
    assertEquals(refSchema.get$ref(), "#/components/schemas/bar");
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test)

Example 33 with Schema

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

the class SchemaProcessorTest method testProcessComposedSchema.

@Test
public void testProcessComposedSchema() throws Exception {
    setupPropertyAndExternalRefProcessors();
    final String ref1 = "http://my.company.com/path/to/file.json#/foo/bar";
    final String ref2 = "http://my.company.com/path/to/file.json#/this/that";
    final String ref3 = "http://my.company.com/path/to/file.json#/hello/world";
    SchemaProcessor modelProcessor = new SchemaProcessor(cache, openAPI);
    new Expectations() {

        {
            externalRefProcessor.processRefToExternalSchema(ref1, RefFormat.URL);
            times = 1;
            result = "bar";
            externalRefProcessor.processRefToExternalSchema(ref2, RefFormat.URL);
            times = 1;
            result = "that";
            externalRefProcessor.processRefToExternalSchema(ref3, RefFormat.URL);
            times = 1;
            result = "world";
        }
    };
    ComposedSchema composedModel = new ComposedSchema();
    composedModel.addAllOfItem(new Schema().$ref(ref1));
    composedModel.addAllOfItem(new Schema().$ref(ref2));
    composedModel.addAllOfItem(new Schema().$ref(ref3));
    modelProcessor.processSchema(composedModel);
    new FullVerifications() {

        {
            externalRefProcessor.processRefToExternalSchema(ref1, RefFormat.URL);
            times = 1;
            externalRefProcessor.processRefToExternalSchema(ref2, RefFormat.URL);
            times = 1;
            externalRefProcessor.processRefToExternalSchema(ref3, RefFormat.URL);
            times = 1;
        }
    };
    // child
    assertEquals(composedModel.getAllOf().get(0).get$ref(), "#/components/schemas/bar");
    // parent
    assertEquals(composedModel.getAllOf().get(1).get$ref(), "#/components/schemas/that");
    assertEquals(composedModel.getAllOf().get(2).get$ref(), "#/components/schemas/world");
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test)

Example 34 with Schema

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

the class SchemaProcessorTest method testProcessMapProperty_AdditionalPropertiesIsRefProperty.

@Test
public void testProcessMapProperty_AdditionalPropertiesIsRefProperty() throws Exception {
    expectCreationOfExternalRefProcessor();
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    final Schema refProperty = new Schema().$ref(ref);
    refProperty.setAdditionalProperties(refProperty);
    expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar");
    new SchemaProcessor(cache, openAPI).processSchema(refProperty);
    new FullVerifications() {

        {
        }
    };
    assertEquals((((Schema) refProperty.getAdditionalProperties()).get$ref()), "#/components/schemas/bar");
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test)

Example 35 with Schema

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

the class SchemaProcessorTest method testProcessArraySchema.

@Test
public void testProcessArraySchema() throws Exception {
    Schema property = new Schema();
    SchemaProcessor propertyProcessor = new SchemaProcessor(cache, openAPI);
    propertyProcessor.processSchema(property);
    ArraySchema model = new ArraySchema();
    model.setItems(property);
    SchemaProcessor schemaProcessor = new SchemaProcessor(cache, openAPI);
    schemaProcessor.processSchema(model);
    assertEquals(property, model.getItems());
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test)

Aggregations

Schema (io.swagger.v3.oas.models.media.Schema)481 Test (org.testng.annotations.Test)464 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)370 StringSchema (io.swagger.v3.oas.models.media.StringSchema)311 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)258 OpenAPI (io.swagger.v3.oas.models.OpenAPI)250 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)246 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)239 MapSchema (io.swagger.v3.oas.models.media.MapSchema)170 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)116 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)99 DateSchema (io.swagger.v3.oas.models.media.DateSchema)96 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)86 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)86 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)84 Operation (io.swagger.v3.oas.models.Operation)72 MediaType (io.swagger.v3.oas.models.media.MediaType)72 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)70 Parameter (io.swagger.v3.oas.models.parameters.Parameter)69 Components (io.swagger.v3.oas.models.Components)67