Skip to content

Commit

Permalink
Merge branch 'master' into fix/annotation-introspector-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-ramagiri authored Nov 9, 2024
2 parents 4a24f4d + dc8785e commit 9223330
Show file tree
Hide file tree
Showing 88 changed files with 3,335 additions and 222 deletions.
3 changes: 3 additions & 0 deletions CI/post-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ sc_find="io.swagger.core.v3:swagger-jaxrs2:$SC_VERSION"
sc_replace="io.swagger.core.v3:swagger-jaxrs2:$SC_NEXT_VERSION-SNAPSHOT"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java

sc_find="<version>$SC_VERSION<\/version>"
sc_replace="<version>$SC_NEXT_VERSION-SNAPSHOT<\/version>"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-java17-support/pom.xml

#####################
### Copy scripts to temp folder, as they are not available when checking out different branch or repo
Expand Down
4 changes: 4 additions & 0 deletions CI/prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ sc_find="<version>$SC_LAST_RELEASE<\/version>"
sc_replace="<version>$SC_VERSION<\/version>"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-maven-plugin/README.md

sc_find="<version>$SC_LAST_RELEASE<\/version>"
sc_replace="<version>$SC_VERSION<\/version>"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swaggerjava17-support/pom.xml

#####################
### build and test maven ###
#####################
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ The OpenAPI Specification has undergone several revisions since initial creation

Swagger core Version | Release Date | OpenAPI Spec compatibility | Notes | Status
------------------------- | ------------ | -------------------------- | ----- | ----
2.2.23 (**current stable**)| 2024-08-28 | 3.x | [tag v2.2.23](https://github.com/swagger-api/swagger-core/tree/v2.2.23) | Supported
2.2.25 (**current stable**)| 2024-10-02 | 3.x | [tag v2.2.25](https://github.com/swagger-api/swagger-core/tree/v2.2.25) | Supported
2.2.24 | 2024-09-23 | 3.x | [tag v2.2.24](https://github.com/swagger-api/swagger-core/tree/v2.2.24) | Supported
2.2.23 | 2024-08-28 | 3.x | [tag v2.2.23](https://github.com/swagger-api/swagger-core/tree/v2.2.23) | Supported
2.2.22 | 2024-05-15 | 3.x | [tag v2.2.22](https://github.com/swagger-api/swagger-core/tree/v2.2.22) | Supported
2.2.21 | 2024-03-20 | 3.x | [tag v2.2.21](https://github.com/swagger-api/swagger-core/tree/v2.2.21) | Supported
2.2.20 | 2023-12-19 | 3.x | [tag v2.2.20](https://github.com/swagger-api/swagger-core/tree/v2.2.20) | Supported
Expand Down Expand Up @@ -116,7 +118,7 @@ You need the following installed and available in your $PATH:
* Jackson 2.4.5 or greater


### To build from source (currently 2.2.24-SNAPSHOT)
### To build from source (currently 2.2.26-SNAPSHOT)
```
# first time building locally
mvn -N
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.2.24-SNAPSHOT</version>
<version>2.2.26-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
boolean writeOnly() default false;

/**
* Allows to specify the access mode (AccessMode.READ_ONLY, READ_WRITE)
* Allows to specify the access mode (AccessMode.READ_ONLY, WRITE_ONLY, READ_WRITE)
*
* AccessMode.READ_ONLY: value will not be written to during a request but may be returned during a response.
* AccessMode.WRITE_ONLY: value will only be written to during a request but not returned during a response.
Expand All @@ -246,7 +246,7 @@
* @return the accessMode for this schema (property)
*
*/
AccessMode accessMode() default AccessMode.AUTO;
AccessMode accessMode() default AccessMode.AUTO;

/**
* Provides an example of the schema. When associated with a specific media type, the example string shall be parsed by the consumer to be treated as an object or an array.
Expand Down Expand Up @@ -554,6 +554,14 @@ enum RequiredMode {
NOT_REQUIRED;
}

enum SchemaResolution {
AUTO,
DEFAULT,
INLINE,
ALL_OF,
ALL_OF_REF;
}

/**
* Allows to specify the dependentRequired value
**
Expand Down Expand Up @@ -616,4 +624,17 @@ enum RequiredMode {
*/
@OpenAPI31
String _const() default "";

/**
* Allows to specify the schema resolution mode for object schemas
*
* SchemaResolution.DEFAULT: bundled into components/schemas, $ref with no siblings
* SchemaResolution.INLINE: inline schema, no $ref
* SchemaResolution.ALL_OF: bundled into components/schemas, $ref and any context annotation resolution into allOf
* SchemaResolution.ALL_OF_REF: bundled into components/schemas, $ref into allOf, context annotation resolution into root
*
* @return the schema resolution mode for this schema
*
*/
SchemaResolution schemaResolution() default SchemaResolution.AUTO;
}
2 changes: 1 addition & 1 deletion modules/swagger-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.2.24-SNAPSHOT</version>
<version>2.2.26-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public ModelConverters(boolean openapi31) {
}
}

public ModelConverters(boolean openapi31, Schema.SchemaResolution schemaResolution) {
converters = new CopyOnWriteArrayList<>();
if (openapi31) {
converters.add(new ModelResolver(Json31.mapper()).openapi31(true).schemaResolution(schemaResolution));
} else {
converters.add(new ModelResolver(Json.mapper()).schemaResolution(schemaResolution));
}
}

public Set<String> getSkippedPackages() {
return skippedPackages;
}
Expand All @@ -61,6 +70,30 @@ public static ModelConverters getInstance(boolean openapi31) {
return SINGLETON;
}

public static void reset() {
synchronized (ModelConverters.class) {
SINGLETON = null;
SINGLETON31 = null;
}
}

public static ModelConverters getInstance(boolean openapi31, Schema.SchemaResolution schemaResolution) {
synchronized (ModelConverters.class) {
if (openapi31) {
if (SINGLETON31 == null) {
SINGLETON31 = new ModelConverters(openapi31, Schema.SchemaResolution.DEFAULT);
init(SINGLETON31);
}
return SINGLETON31;
}
if (SINGLETON == null) {
SINGLETON = new ModelConverters(openapi31, schemaResolution);
init(SINGLETON);
}
return SINGLETON;
}
}

private static void init(ModelConverters converter) {
converter.addPackageToSkip("java.lang");
converter.addPackageToSkip("groovy.lang");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public OpenAPI filter(OpenAPI openAPI, OpenAPISpecFilter filter, Map<String, Lis

if (filteredOpenAPI.getWebhooks() != null) {
for (String resourcePath : filteredOpenAPI.getWebhooks().keySet()) {
PathItem pathItem = filteredOpenAPI.getPaths().get(resourcePath);
PathItem pathItem = filteredOpenAPI.getWebhooks().get(resourcePath);

PathItem filteredPathItem = filterPathItem(filter, pathItem, resourcePath, params, cookies, headers);
PathItem clonedPathItem = cloneFilteredPathItem(filter,filteredPathItem, resourcePath, params, cookies, headers, allowedTags, filteredTags);
Expand Down Expand Up @@ -350,38 +350,98 @@ private void addPathItemSchemaRef(PathItem pathItem, Set<String> referencedDefin
Map<PathItem.HttpMethod, Operation> ops = pathItem.readOperationsMap();
for (Operation op : ops.values()) {
if (op.getRequestBody() != null) {
addContentSchemaRef(op.getRequestBody().getContent(), referencedDefinitions);
addRequestBodySchemaRef(op.getRequestBody(), referencedDefinitions);
}
if (op.getResponses() != null) {
for (String keyResponses : op.getResponses().keySet()) {
ApiResponse response = op.getResponses().get(keyResponses);
if (response.getHeaders() != null) {
for (String keyHeaders : response.getHeaders().keySet()) {
Header header = response.getHeaders().get(keyHeaders);
addSchemaRef(header.getSchema(), referencedDefinitions);
addContentSchemaRef(header.getContent(), referencedDefinitions);
}
}
addContentSchemaRef(response.getContent(), referencedDefinitions);
addApiResponseSchemaRef(response, referencedDefinitions);
}
}
if (op.getParameters() != null) {
for (Parameter parameter : op.getParameters()) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
addParameterSchemaRef(parameter, referencedDefinitions);
}
}
if (op.getCallbacks() != null) {
for (String keyCallback : op.getCallbacks().keySet()) {
Callback callback = op.getCallbacks().get(keyCallback);
for (PathItem callbackPathItem : callback.values()) {
addPathItemSchemaRef(callbackPathItem, referencedDefinitions);
}
addCallbackSchemaRef(callback, referencedDefinitions);
}
}
}
}

private void addApiResponseSchemaRef(ApiResponse response, Set<String> referencedDefinitions) {
if (response.getHeaders() != null) {
for (String keyHeaders : response.getHeaders().keySet()) {
Header header = response.getHeaders().get(keyHeaders);
addHeaderSchemaRef(header, referencedDefinitions);
}
}
addContentSchemaRef(response.getContent(), referencedDefinitions);
}

private void addRequestBodySchemaRef(RequestBody requestBody, Set<String> referencedDefinitions) {
addContentSchemaRef(requestBody.getContent(), referencedDefinitions);
}

private void addParameterSchemaRef(Parameter parameter, Set<String> referencedDefinitions) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
}

private void addHeaderSchemaRef(Header header, Set<String> referencedDefinitions) {
addSchemaRef(header.getSchema(), referencedDefinitions);
addContentSchemaRef(header.getContent(), referencedDefinitions);
}

private void addCallbackSchemaRef(Callback callback, Set<String> referencedDefinitions){
for (PathItem callbackPathItem : callback.values()) {
addPathItemSchemaRef(callbackPathItem, referencedDefinitions);
}
}

private void addComponentsSchemaRef(Components components, Set<String> referencedDefinitions){

if (components.getResponses() != null){
for (String resourcePath : components.getResponses().keySet()) {
ApiResponse apiResponse = components.getResponses().get(resourcePath);
addApiResponseSchemaRef(apiResponse, referencedDefinitions);
}
}
if (components.getRequestBodies() != null){
for (String requestBody : components.getRequestBodies().keySet()) {
RequestBody requestBody1 = components.getRequestBodies().get(requestBody);
addRequestBodySchemaRef(requestBody1, referencedDefinitions);
}
}
if (components.getParameters() != null){
for (String parameter : components.getParameters().keySet()) {
Parameter resourceParam = components.getParameters().get(parameter);
addParameterSchemaRef(resourceParam, referencedDefinitions);
}
}
if (components.getHeaders() != null){
for (String header : components.getHeaders().keySet()) {
Header resourceHeader = components.getHeaders().get(header);
addHeaderSchemaRef(resourceHeader, referencedDefinitions);
}
}
if (components.getCallbacks() != null){
for (String callback : components.getCallbacks().keySet()){
Callback resourceCallback = components.getCallbacks().get(callback);
addCallbackSchemaRef(resourceCallback, referencedDefinitions);
}
}
if (components.getPathItems() != null){
for (String resourcePath : components.getPathItems().keySet()){
PathItem pathItem = components.getPathItems().get(resourcePath);
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
}

protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) {

if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) {
Expand All @@ -395,6 +455,16 @@ protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) {
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
if (openApi.getWebhooks() != null){
for (String resourcePath : openApi.getWebhooks().keySet()) {
PathItem pathItem = openApi.getWebhooks().get(resourcePath);
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
if (openApi.getComponents() != null){
Components components = openApi.getComponents();
addComponentsSchemaRef(components, referencedDefinitions);
}

referencedDefinitions.addAll(resolveAllNestedRefs(referencedDefinitions, referencedDefinitions, openApi));
openApi.getComponents()
Expand Down
Loading

0 comments on commit 9223330

Please sign in to comment.