Search in sources :

Example 1 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class EnumPropertyTest method testEnumRefPropertyGlobalNotAffectingNonEnums.

@Test(description = "it should not affect non-enum models when the enumsAsRef property is enabled globally")
public void testEnumRefPropertyGlobalNotAffectingNonEnums() {
    ModelResolver.enumsAsRef = true;
    Schema schema = context.resolve(new AnnotatedType(Model1979.class));
    final Map<String, Schema> models = context.getDefinedModels();
    final String yaml = "Model1979:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: string\n" + "      nullable: true";
    SerializationMatchers.assertEqualsToYaml(models, yaml);
    ModelResolver.enumsAsRef = false;
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) Model1979(io.swagger.v3.core.oas.models.Model1979) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 2 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class EnumPropertyTest method testEnumRefPropertyWithFQNTypeNameResolver.

@Test(description = "it should read a model with an enum property as a reference with fqn TypeNameResolver")
public void testEnumRefPropertyWithFQNTypeNameResolver() {
    TypeNameResolver.std.setUseFqn(true);
    Schema schema = context.resolve(new AnnotatedType(ModelWithEnumRefProperty.class));
    final Map<String, Schema> models = context.getDefinedModels();
    final String yaml = "io.swagger.v3.core.oas.models.ModelWithEnumRefProperty:\n" + "  type: object\n" + "  properties:\n" + "    a:\n" + "      $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" + "    b:\n" + "      $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" + "    c:\n" + "      $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestSecondEnum'\n" + "    d:\n" + "      type: string\n" + "      enum:\n" + "      - A_PRIVATE\n" + "      - A_PUBLIC\n" + "      - A_SYSTEM\n" + "      - A_INVITE_ONLY\n" + "io.swagger.v3.core.oas.models.TestEnum:\n" + "  type: string\n" + "  enum:\n" + "  - PRIVATE\n" + "  - PUBLIC\n" + "  - SYSTEM\n" + "  - INVITE_ONLY\n" + "io.swagger.v3.core.oas.models.TestSecondEnum:\n" + "  type: string\n" + "  enum:\n" + "  - A_PRIVATE\n" + "  - A_PUBLIC\n" + "  - A_SYSTEM\n" + "  - A_INVITE_ONLY\n";
    TypeNameResolver.std.setUseFqn(false);
    SerializationMatchers.assertEqualsToYaml(models, yaml);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ModelWithEnumRefProperty(io.swagger.v3.core.oas.models.ModelWithEnumRefProperty) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 3 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class ParameterDeSerializationTest method testIssue1765.

@Test(description = "should serialize correctly typed numeric enums")
public void testIssue1765() throws Exception {
    String yaml = "openapi: '3.0.1'\n" + "paths:\n" + "  /test:\n" + "    get:\n" + "      parameters:\n" + "      - name: \"days\"\n" + "        in: \"path\"\n" + "        required: true\n" + "        schema:\n" + "          type: \"integer\"\n" + "          format: \"int32\"\n" + "          enum:\n" + "          - 1\n" + "          - 2\n" + "          - 3\n" + "          - 4\n" + "          - 5\n" + "      responses:\n" + "        default:\n" + "          description: great";
    OpenAPI swagger = Yaml.mapper().readValue(yaml, OpenAPI.class);
    SerializationMatchers.assertEqualsToYaml(swagger, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 4 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class JsonDeserializationTest method testNullEnumItem.

@Test(description = "Deserialize null enum item")
public void testNullEnumItem() throws Exception {
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      tags:\n" + "      - MyTag\n" + "      summary: Operation Summary\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "      parameters:\n" + "      - name: subscriptionId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: integer\n" + "      description: some int values with null\n" + "      format: int32\n" + "      enum:\n" + "      - 1\n" + "      - 2\n" + "      - null\n";
    OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
    assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList(1, 2, null));
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      tags:\n" + "      - MyTag\n" + "      summary: Operation Summary\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "      parameters:\n" + "      - name: subscriptionId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: string\n" + "      description: some int values with null\n" + "      enum:\n" + "      - 1\n" + "      - 2\n" + "      - null\n";
    oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
    assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList("1", "2", null));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 5 with Yaml

use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.

the class OpenAPI3_1DeserializationTest method deserializePetstore3_0.

@Test
public void deserializePetstore3_0() throws IOException {
    final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/petstore-3.0.yaml");
    final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class);
    assertNotNull(swagger);
    assertEquals(swagger.getInfo().getLicense().getIdentifier(), null);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)63 OpenAPI (io.swagger.v3.oas.models.OpenAPI)55 Schema (io.swagger.v3.oas.models.media.Schema)15 Components (io.swagger.v3.oas.models.Components)13 Info (io.swagger.v3.oas.models.info.Info)13 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)9 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)8 SpecFilter (io.swagger.v3.core.filter.SpecFilter)8 StringSchema (io.swagger.v3.oas.models.media.StringSchema)8 AfterTest (org.testng.annotations.AfterTest)6 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)5 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)4 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 IOException (java.io.IOException)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)3 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)3