Search in sources :

Example 66 with Yaml

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

the class OpenAPIV3ParserTest method testIssue901_2.

@Test
public void testIssue901_2() {
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec2.yaml", null, options).getOpenAPI();
    assertNotNull(openAPI);
    assertNotNull(openAPI.getComponents());
    ArraySchema arraySchema = (ArraySchema) openAPI.getComponents().getSchemas().get("Test.Definition").getProperties().get("stuff");
    String internalRef = arraySchema.getItems().get$ref();
    assertEquals(internalRef, "#/components/schemas/TEST.THING.OUT.Stuff");
}
Also used : ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 67 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 68 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 69 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 70 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)

Aggregations

Test (org.testng.annotations.Test)188 OpenAPI (io.swagger.v3.oas.models.OpenAPI)151 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)121 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)94 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)62 Schema (io.swagger.v3.oas.models.media.Schema)58 StringSchema (io.swagger.v3.oas.models.media.StringSchema)49 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)47 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)43 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)42 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)38 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)35 MapSchema (io.swagger.v3.oas.models.media.MapSchema)33 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)25 DateSchema (io.swagger.v3.oas.models.media.DateSchema)25 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)25 Parameter (io.swagger.v3.oas.models.parameters.Parameter)18 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)18 Components (io.swagger.v3.oas.models.Components)15 Info (io.swagger.v3.oas.models.info.Info)14