-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/EAlf91/springdoc-openapi in…
…to EAlf91-main
- Loading branch information
Showing
8 changed files
with
444 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...doc-openapi-hateoas-tests/src/test/java/test/org/springdoc/api/app9/FooConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package test.org.springdoc.api.app9; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.media.ArraySchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import io.swagger.v3.oas.models.tags.Tag; | ||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class FooConfiguration { | ||
@Bean | ||
OpenAPI customOpenApi() { | ||
return new OpenAPI() | ||
.components(new Components().addSecuritySchemes("bearerScheme", | ||
new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("bearer") | ||
.bearerFormat("JWT")) | ||
.addSchemas("FeedResponse", feedResponseSchema())) | ||
.info(new Info() | ||
.title("Response API") | ||
.description("API for some response") | ||
.version("0.0.1") | ||
.contact(new Contact() | ||
.name("EAlf91"))) | ||
.tags(List.of(new Tag() | ||
.name("ResponseTag") | ||
.description("ResponseTag for API"), | ||
new Tag() | ||
.name("ResponseData") | ||
.description("Version 2 ResponseApi"))); | ||
|
||
} | ||
|
||
private Schema<?> feedResponseSchema() { | ||
Schema<?> schema = new Schema<>(); | ||
schema.addProperty("_links", linkSchema()); | ||
schema.addProperty("data", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/ResponseData"))); | ||
return schema; | ||
} | ||
|
||
private Schema<?> linkSchema() { | ||
Schema<?> linkSchema = new Schema<>(); | ||
linkSchema.addProperty("next", new Schema<>().$ref("#/components/schemas/Link").example("http://localhost:8080/some-link")); | ||
linkSchema.addProperty("self", new Schema<>().$ref("#/components/schemas/Link").example("http://localhost:8080/some-other-link")); | ||
return linkSchema; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...oc-openapi-hateoas-tests/src/test/java/test/org/springdoc/api/app9/SpringDocApp9Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* | ||
* * Copyright 2019-2020 the original author or authors. | ||
* * | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.app9; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import test.org.springdoc.api.AbstractSpringDocTest; | ||
|
||
public class SpringDocApp9Test extends AbstractSpringDocTest { | ||
|
||
@SpringBootApplication | ||
static class SpringDocTestApp { | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...pi-hateoas-tests/src/test/java/test/org/springdoc/api/app9/application/FooController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package test.org.springdoc.api.app9.application; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
import test.org.springdoc.api.app9.application.dto.ResponseData; | ||
import test.org.springdoc.api.app9.application.dto.FeedResponse; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
@Tag(name = "ResponseDataController") | ||
@RestController | ||
@RequestMapping(value = "/some-route", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class FooController { | ||
|
||
|
||
|
||
|
||
@Operation(summary = "Get all data", description = "Get all data") | ||
@GetMapping(value = "foo/{id}") | ||
@ResponseStatus(HttpStatus.OK) | ||
public FeedResponse getFoo(@PathVariable("id") UUID id) { | ||
var dataList = List.of(ResponseData.builder().dataId(id).build()); | ||
return FeedResponse.createForResponseData(dataList, UUID.randomUUID()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...hateoas-tests/src/test/java/test/org/springdoc/api/app9/application/dto/FeedResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package test.org.springdoc.api.app9.application.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
import org.springframework.hateoas.IanaLinkRelations; | ||
import org.springframework.hateoas.RepresentationModel; | ||
import test.org.springdoc.api.app9.application.FooController; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Builder(access = AccessLevel.PACKAGE) | ||
@EqualsAndHashCode(callSuper = true) | ||
public class FeedResponse extends RepresentationModel<FeedResponse> { | ||
@NotNull | ||
@JsonProperty("data") | ||
private final List<ResponseData> data; | ||
|
||
public static FeedResponse createForResponseData(@NotNull List<ResponseData> responseData, UUID uuid) { | ||
var feedResponse = new FeedResponse(responseData); | ||
feedResponse.add(linkTo(methodOn(FooController.class).getFoo(uuid)).withSelfRel()); | ||
|
||
|
||
feedResponse.add(linkTo(methodOn(FooController.class).getFoo(uuid)).withRel(IanaLinkRelations.NEXT)); | ||
|
||
return feedResponse; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...hateoas-tests/src/test/java/test/org/springdoc/api/app9/application/dto/ResponseData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package test.org.springdoc.api.app9.application.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
import java.util.UUID; | ||
|
||
@Builder | ||
public record ResponseData( | ||
@JsonProperty(value = "DATA_ID", required = true) | ||
@NotNull | ||
UUID dataId, | ||
@JsonProperty(value = "DATE", required = true) | ||
@NotNull | ||
@Schema(example = "2024-03-27", format = "date") | ||
LocalDate date | ||
) {} |
142 changes: 142 additions & 0 deletions
142
springdoc-openapi-tests/springdoc-openapi-hateoas-tests/src/test/resources/results/app9.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "Response API", | ||
"description": "API for some response", | ||
"contact": { | ||
"name": "EAlf91" | ||
}, | ||
"version": "0.0.1" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"tags": [ | ||
{ | ||
"name": "ResponseTag", | ||
"description": "ResponseTag for API" | ||
}, | ||
{ | ||
"name": "ResponseData", | ||
"description": "Version 2 ResponseApi" | ||
} | ||
], | ||
"paths": { | ||
"/some-route/foo/{id}": { | ||
"get": { | ||
"tags": [ | ||
"ResponseDataController" | ||
], | ||
"summary": "Get all data", | ||
"description": "Get all data", | ||
"operationId": "getFoo", | ||
"parameters": [ | ||
{ | ||
"name": "id", | ||
"in": "path", | ||
"required": true, | ||
"schema": { | ||
"type": "string", | ||
"format": "uuid" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/FeedResponse" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"FeedResponse": { | ||
"type": "object", | ||
"properties": { | ||
"_links": { | ||
"type": "object", | ||
"properties": { | ||
"next": { | ||
"$ref": "#/components/schemas/Link" | ||
}, | ||
"self": { | ||
"$ref": "#/components/schemas/Link" | ||
} | ||
} | ||
}, | ||
"data": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/ResponseData" | ||
} | ||
} | ||
} | ||
}, | ||
"ResponseData": { | ||
"required": [ | ||
"DATA_ID", | ||
"DATE" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"DATA_ID": { | ||
"type": "string", | ||
"format": "uuid" | ||
}, | ||
"DATE": { | ||
"type": "string", | ||
"format": "date", | ||
"example": "2024-03-27" | ||
} | ||
} | ||
}, | ||
"Link": { | ||
"type": "object", | ||
"properties": { | ||
"href": { | ||
"type": "string" | ||
}, | ||
"hreflang": { | ||
"type": "string" | ||
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"deprecation": { | ||
"type": "string" | ||
}, | ||
"profile": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"templated": { | ||
"type": "boolean" | ||
} | ||
} | ||
} | ||
}, | ||
"securitySchemes": { | ||
"bearerScheme": { | ||
"type": "http", | ||
"scheme": "bearer", | ||
"bearerFormat": "JWT" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.