Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAS 3.1 Initial support - Schema properties support in annotations - Enhanced Response Schema resolving #4129

Merged
merged 43 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1da7289
OpenAPI 3.1 - initial support
frantuma Apr 5, 2021
585266e
OpenAPI 3.1 - hidden Schema Member for schema implementation
frantuma Jun 8, 2021
223b950
OpenAPI 3.1 - initial full semantic serialization
frantuma Jun 21, 2021
e2fb154
OpenAPI 3.1 - initial models, (de)serializers, mixins, annotations
frantuma Sep 14, 2021
3924016
added path items to components object
HugoMario Sep 23, 2021
2b45f4d
added summary field on Info object
HugoMario Sep 23, 2021
deba585
added specfic extensions for Discriminator object
HugoMario Sep 23, 2021
0b6923e
added set collection to allow roles for non oauth2 nor openIdConnect …
HugoMario Sep 24, 2021
1c68947
handled 'x-oai-' and 'x-oas-' prefixes for oas 3.1 extensions.
HugoMario Sep 24, 2021
915fc4f
added jsonSchemaDialect field.
HugoMario Sep 24, 2021
4947f06
reverted roles changes on security schema class.
HugoMario Sep 30, 2021
a0fecf3
added oas 3.1 annotation to `addExtension31` method and removed TODO …
HugoMario Sep 30, 2021
160cee9
added extensions on Discriminator equals method
HugoMario Sep 30, 2021
b8e7d73
removed addExtension31 method from Schema class
HugoMario Sep 30, 2021
86f351e
Revert "added jsonSchemaDialect field."
HugoMario Oct 1, 2021
a2c3a3b
added `jsonSchemaDialect` field to OpenAPI class.
HugoMario Oct 1, 2021
8050cd0
tweaked fluent accessors on Link, Encoding, ApiResponse and Operation…
HugoMario Oct 1, 2021
291a8d0
OpenAPI 3.1 - fix tests after accessors fixes
frantuma Oct 4, 2021
301bf51
updated oas 3.1 properties on schema class.
HugoMario Dec 3, 2021
2e1f9eb
removed extra line
HugoMario Dec 4, 2021
9d595e9
add prefixItems fields and methods
gracekarina Dec 12, 2021
9b070ac
added mixin to handle new openapi 3.1 fields: info.summary, license.i…
HugoMario Nov 22, 2021
90fd9bb
added serialization tests
HugoMario Nov 22, 2021
f883d79
renamed info mixin
HugoMario Nov 22, 2021
e5d955e
added discriminator mixins for oas 3.0 and 3.1
HugoMario Nov 22, 2021
e49ae0c
added deserialization tests
HugoMario Nov 24, 2021
f9fcacd
fixed tests errors related to info mixin class
HugoMario Nov 24, 2021
644d4cc
fixed tests error related to license mixin class
HugoMario Nov 24, 2021
47e332d
added summary property, on model class with ref property without it, …
HugoMario Dec 10, 2021
20ba0ec
updated callback serializer
HugoMario Dec 13, 2021
f44b6a8
updated callback and parameter deserializer, and made test to check r…
HugoMario Dec 15, 2021
acf0193
updated securityscheme deserialization class and updated serializatio…
HugoMario Dec 29, 2021
4c1d7f1
added deserialization test for OAS 3.0 using a OAS 3.1 definition
HugoMario Dec 29, 2021
e9f4884
update type for unevaluatedProperties property
HugoMario Dec 30, 2021
b71aa06
added tests to check that ref property is deserialized along other pr…
HugoMario Jan 3, 2022
47bde2b
added tests to check ref serialization siblings.
HugoMario Jan 5, 2022
ce08d0a
added basic file for 3.1 testing
gracekarina Jan 17, 2022
9b9025a
OpenAPI 3.1 - various fixes
frantuma Feb 18, 2022
085c2eb
bump version to 2.2.0-SNAPSHOT
frantuma Feb 21, 2022
158a57a
refs #3633, #2891, #3433, #3547 - properties and additionalProperties…
frantuma Feb 22, 2022
eaaf908
refs #3870 - enhanced response schema resolving
frantuma Feb 22, 2022
babc025
wrap owasp plugin within profile
frantuma Feb 22, 2022
1730497
update maven and wrapper versions
frantuma Feb 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.3";
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
Expand Down
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.6.jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You need the following installed and available in your $PATH:
* Jackson 2.4.5 or greater


### To build from source (currently 2.1.14-SNAPSHOT)
### To build from source (currently 2.2.0-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.1.14-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@
**/
Schema schema() default @Schema();

/**
* The schema properties defined for schema provided in @Schema
*
* @since 2.2.0
* @return the schema properties
*/
SchemaProperty[] schemaProperties() default {};

/**
* The schema properties defined for schema provided in @Schema
*
* @since 2.2.0
* @return the schema properties
*/
Schema additionalPropertiesSchema() default @Schema();

/**
* The schema of the array that defines the type used for the content.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2017 SmartBear Software
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.swagger.v3.oas.annotations.media;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;

/**
* Container for repeatable {@link PatternProperty} annotation
*
* @see PatternProperty
*/
@Target({FIELD, METHOD, PARAMETER, TYPE, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface PatternProperties {
/**
* An array of PatternProperty annotations
*
* @return the array of the PatternProperty
**/
PatternProperty[] value() default {};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright 2021 SmartBear Software
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.swagger.v3.oas.annotations.media;

import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;

/**
* The annotation may be used in OpenAPI 3.1 schemas / JSON Schema.
*
* @see <a target="_new" href="https://tools.ietf.org/html/draft-bhutton-json-schema-00#section-10.3.2.2">JSON Schema section 10.3.2.2</a>
* @see Schema
*
* @since 2.1.8
**/
@Target({FIELD, METHOD, PARAMETER, TYPE, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(PatternProperties.class)
public @interface PatternProperty {
/**
* The regex.
*
* @return the regex
**/
String regex() default "";

/**
* The schema to validate against for properties matching the regex.
*
* @return the schema
**/
Schema schema() default @Schema();

/**
* The schema of the array to validate against for properties matching the regex.
*
* @return the schema of the array
*/
ArraySchema array() default @ArraySchema();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.file.AccessMode;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
Expand Down Expand Up @@ -329,10 +328,29 @@
*/
Extension[] extensions() default {};

/**
* Allows to specify the additionalProperties value
*
* AdditionalPropertiesValue.TRUE: set to TRUE
* AdditionalPropertiesValue.FALSE: set to FALSE
* AdditionalPropertiesValue.USE_ADDITIONAL_PROPERTIES_ANNOTATION: resolve from @Content.additionalPropertiesSchema
*
* @since 2.2.0
* @return the accessMode for this schema (property)
*
*/
AdditionalPropertiesValue additionalProperties() default AdditionalPropertiesValue.USE_ADDITIONAL_PROPERTIES_ANNOTATION;

enum AccessMode {
AUTO,
READ_ONLY,
WRITE_ONLY,
READ_WRITE;
}

enum AdditionalPropertiesValue {
TRUE,
FALSE,
USE_ADDITIONAL_PROPERTIES_ANNOTATION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2017 SmartBear Software
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.swagger.v3.oas.annotations.media;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;

/**
* Container for repeatable {@link SchemaProperty} annotation
*
* @see SchemaProperty
*/
@Target({FIELD, METHOD, PARAMETER, TYPE, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface SchemaProperties {
/**
* An array of SchemaProperty annotations
*
* @return the array of the SchemaProperty
**/
SchemaProperty[] value() default {};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2021 SmartBear Software
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.swagger.v3.oas.annotations.media;

import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;

/**
* The annotation may be used to define properties for an Object Schema
*
* @see Schema
*
* @since 2.1.8
**/
@Target({FIELD, METHOD, PARAMETER, TYPE, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(SchemaProperties.class)
public @interface SchemaProperty {
/**
* The name.
*
* @return the name
**/
String name() default "";

/**
* The schema of the property.
*
* @return the schema
**/
Schema schema() default @Schema();

/**
* The schema of the array.
*
* @return the schema of the array
*/
ArraySchema array() default @ArraySchema();

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@
**/
String ref() default "";

/**
* Set to true to resolve the response schema from method return type
*
* @since 2.2.0
**/
boolean useReturnTypeSchema() default false;

}
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.1.14-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ public ResolvedSchema readAllAsResolvedSchema(Type type) {
}
public ResolvedSchema readAllAsResolvedSchema(AnnotatedType type) {
if (shouldProcess(type.getType())) {
ModelConverterContextImpl context = new ModelConverterContextImpl(
converters);

ResolvedSchema resolvedSchema = new ResolvedSchema();
resolvedSchema.schema = context.resolve(type);
resolvedSchema.referencedSchemas = context.getDefinedModels();

return resolvedSchema;
return resolveAsResolvedSchema(type);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ public void serialize(
Callback value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {

// has extensions
if (value != null && value.getExtensions() != null && !value.getExtensions().isEmpty()) {
jgen.writeStartObject();

// not a ref
if (StringUtils.isBlank(value.get$ref())) {
if (!value.isEmpty()) {
// write map
for (Entry<String, PathItem> entry: value.entrySet()) {
jgen.writeObjectField(entry.getKey() , entry.getValue());
}
}
} else { // handle ref schema serialization skipping all other props
} else { // handle ref schema serialization skipping all other props ...
jgen.writeStringField("$ref", value.get$ref());
}
for (String ext: value.getExtensions().keySet()) {
Expand Down
Loading