Search in sources :

Example 81 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testResponseWithRef.

@Test(description = "Responses with ref")
public void testResponseWithRef() {
    Components components = new Components();
    components.addResponses("invalidJWT", new ApiResponse().description("when JWT token invalid/expired"));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefResponsesResource.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 no inputs and a complex output\n" + "        object\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/SampleResponseSchema'\n" + "        default:\n" + "          description: boo\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/GenericError'\n" + "        \"401\":\n" + "          $ref: '#/components/responses/invalidJWT'\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    GenericError:\n" + "      type: object\n" + "    SampleResponseSchema:\n" + "      type: object\n" + "  responses:\n" + "    invalidJWT:\n" + "      description: when JWT token invalid/expired";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 82 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testTicket3694.

@Test(description = "overridden generic resource methods")
public void testTicket3694() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(Ticket3694ResourceExtendedType.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      tags:\n" + "      - Foo\n" + "      summary: Foo List in Interface\n" + "      operationId: foo\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string\n" + "  /another:\n" + "    post:\n" + "      operationId: another\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694Resource.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      tags:\n" + "      - Foo\n" + "      summary: Foo List in Interface\n" + "      operationId: foo\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string\n" + "  /another:\n" + "    post:\n" + "      operationId: another\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694ResourceSimple.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                type: string";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
    reader = new Reader(new OpenAPI());
    openAPI = reader.read(Ticket3694ResourceSimpleSameReturn.class);
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /bar:\n" + "    post:\n" + "      operationId: bar\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: array\n" + "              items:\n" + "                type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Ticket3694Resource(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694Resource) Ticket3694ResourceSimple(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694ResourceSimple) Ticket3694ResourceSimpleSameReturn(io.swagger.v3.jaxrs2.resources.generics.ticket3694.Ticket3694ResourceSimpleSameReturn) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 83 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class ReaderTest method testMoreResponses.

@Test(description = "More Responses")
public void testMoreResponses() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(EnhancedResponsesResource.class);
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      description: Defines a simple get operation with no inputs and a complex output\n" + "        object\n" + "      operationId: getWithPayloadResponse\n" + "      responses:\n" + "        \"200\":\n" + "          description: voila!\n" + "          content:\n" + "            application/json:\n" + "              schema:\n" + "                $ref: '#/components/schemas/SampleResponseSchema'\n" + "        \"404\":\n" + "          description: not found!\n" + "        \"400\":\n" + "          description: boo\n" + "          content:\n" + "            '*/*':\n" + "              schema:\n" + "                $ref: '#/components/schemas/GenericError'\n" + "      deprecated: true\n" + "components:\n" + "  schemas:\n" + "    GenericError:\n" + "      type: object\n" + "    SampleResponseSchema:\n" + "      type: object\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 84 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class SimpleBuilderTest method testBuilder.

@Test
public void testBuilder() throws Exception {
    // basic metadata
    OpenAPI oai = new OpenAPI().info(new Info().contact(new Contact().email("tony@eatbacon.org").name("Tony the Tam").url("https://foo.bar"))).externalDocs(new ExternalDocumentation().description("read more here").url("http://swagger.io")).addTagsItem(new Tag().name("funky dunky").description("all about neat things")).extensions(new HashMap<String, Object>() {

        {
            put("x-fancy-extension", "something");
        }
    });
    Map<String, Schema> schemas = new HashMap<>();
    schemas.put("StringSchema", new StringSchema().description("simple string schema").minLength(3).maxLength(100).example("it works"));
    schemas.put("IntegerSchema", new IntegerSchema().description("simple integer schema").multipleOf(new BigDecimal(3)).minimum(new BigDecimal(6)));
    oai.components(new Components().schemas(schemas));
    schemas.put("Address", new Schema().description("address object").addProperties("street", new StringSchema().description("the street number")).addProperties("city", new StringSchema().description("city")).addProperties("state", new StringSchema().description("state").minLength(2).maxLength(2)).addProperties("zip", new StringSchema().description("zip code").pattern("^\\d{5}(?:[-\\s]\\d{4})?$").minLength(2).maxLength(2)).addProperties("country", new StringSchema()._enum(new ArrayList<String>() {

        {
            this.add("US");
        }
    })).description("2-digit country code").minLength(2).maxLength(2));
    oai.paths(new Paths().addPathItem("/foo", new PathItem().description("the foo path").get(new Operation().addParametersItem(new QueryParameter().description("Records to skip").required(false).schema(new IntegerSchema())).responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it worked").content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("#/components/schemas/Address")))).addLink("funky", new Link().operationId("getFunky")))))));
    System.out.println(writeJson(oai));
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HashMap(java.util.HashMap) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Paths(io.swagger.v3.oas.models.Paths) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Info(io.swagger.v3.oas.models.info.Info) BigDecimal(java.math.BigDecimal) Contact(io.swagger.v3.oas.models.info.Contact) Content(io.swagger.v3.oas.models.media.Content) Tag(io.swagger.v3.oas.models.tags.Tag) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 85 with Content

use of io.swagger.v3.oas.annotations.media.Content in project swagger-core by swagger-api.

the class Reader method resolveEmptyContent.

protected Content resolveEmptyContent(Produces classProduces, Produces methodProduces) {
    Content content = new Content();
    MediaType mediaType = new MediaType();
    AnnotationsUtils.applyTypes(classProduces == null ? new String[0] : classProduces.value(), methodProduces == null ? new String[0] : methodProduces.value(), content, mediaType);
    return content;
}
Also used : Content(io.swagger.v3.oas.models.media.Content) MediaType(io.swagger.v3.oas.models.media.MediaType)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)121 Test (org.testng.annotations.Test)120 MediaType (io.swagger.v3.oas.models.media.MediaType)70 Schema (io.swagger.v3.oas.models.media.Schema)70 Operation (io.swagger.v3.oas.annotations.Operation)65 Content (io.swagger.v3.oas.models.media.Content)64 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)62 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)57 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)53 Operation (io.swagger.v3.oas.models.Operation)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 StringSchema (io.swagger.v3.oas.models.media.StringSchema)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)42 PathItem (io.swagger.v3.oas.models.PathItem)41 ArrayList (java.util.ArrayList)41 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)40 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)37 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)37 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)33