Search in sources :

Example 81 with Yaml

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

the class ParameterSerializationTest method serializeBodyParameterToYaml.

@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
    final Schema model = new Schema().title("Cat").addProperties("name", new StringSchema());
    final RequestBody p = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(model)));
    final String yaml = "---\n" + "content:\n" + "  '*/*':\n" + "    schema:\n" + "      title: Cat\n" + "      properties:\n" + "        name:\n" + "          type: string";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : Content(io.swagger.v3.oas.models.media.Content) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 82 with Yaml

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

the class JsonSerializationTest method testSerializeNullExample.

@Test
public void testSerializeNullExample() throws Exception {
    final String yaml = ResourceUtils.loadClassResource(getClass(), "specFiles/null-example.yaml");
    OpenAPI deser = Yaml.mapper().readValue(yaml, OpenAPI.class);
    SerializationMatchers.assertEqualsToYaml(deser, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 83 with Yaml

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

the class ReaderTest method testTicket2848.

@Test(description = "array schema required property")
public void testTicket2848() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket2848Resource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      operationId: getter\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/Town'\n" + "components:\n" + "  schemas:\n" + "    Town:\n" + "      required:\n" + "      - streets\n" + "      type: object\n" + "      properties:\n" + "        streets:\n" + "          minItems: 1\n" + "          uniqueItems: true\n" + "          type: array\n" + "          items:\n" + "            type: string\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 84 with Yaml

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

the class ReaderTest method testParameterWithRef.

@Test(description = "Parameter with ref")
public void testParameterWithRef() {
    Components components = new Components();
    components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefParameterResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with a payload complex input object\n" + "      operationId: sendPayload\n" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      deprecated: true\n" + "components:\n" + "  parameters: \n" + "    id:\n" + "      in: query\n" + "      description: Id Description\n" + "      required: true\n" + "      schema:\n" + "        type: integer\n" + "        format: int32\n" + "      example: 1\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 85 with Yaml

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

the class ReaderTest method testSecuritySchemeWithRef.

@Test(description = "SecurityScheme with REf")
public void testSecuritySchemeWithRef() {
    Components components = new Components();
    components.addSecuritySchemes("Security", new SecurityScheme().description("Security Example").name("Security").type(SecurityScheme.Type.OAUTH2).$ref("myOauth2Security").in(SecurityScheme.In.HEADER));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefSecurityResource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      description: description\n" + "      operationId: Operation Id\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "      security:\n" + "      - security_key:\n" + "        - write:pets\n" + "        - read:pets\n" + "components:\n" + "  securitySchemes:\n" + "    Security:\n" + "      type: oauth2\n" + "      description: Security Example\n" + "    myOauth2Security:\n" + "      type: oauth2\n" + "      description: myOauthSecurity Description\n" + "      $ref: '#/components/securitySchemes/Security'\n" + "      in: header\n" + "      flows:\n" + "        implicit:\n" + "          authorizationUrl: http://x.com\n" + "          scopes:\n" + "            write:pets: modify pets in your account\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) 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