From bfb8df4b01a2a93ac5b60cce23e978b527ff38a4 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 8 Apr 2024 12:00:22 -0700 Subject: [PATCH 1/2] Samples regen --- .../petstore/java/.openapi-generator/FILES | 6 + samples/client/petstore/java/README.md | 2 + .../docs/components/schemas/ItemsSchema.md | 253 ++++++++++ .../schemas/MultiPropertiesSchema.md | 463 ++++++++++++++++++ .../components/schemas/ItemsSchema.java | 282 +++++++++++ .../schemas/MultiPropertiesSchema.java | 422 ++++++++++++++++ .../components/schemas/ItemsSchemaTest.java | 18 + .../schemas/MultiPropertiesSchemaTest.java | 18 + .../petstore/python/.openapi-generator/FILES | 4 + samples/client/petstore/python/README.md | 2 + .../docs/components/schema/items_schema.md | 49 ++ .../schema/multi_properties_schema.md | 100 ++++ .../components/schema/items_schema.py | 146 ++++++ .../schema/multi_properties_schema.py | 222 +++++++++ .../components/schemas/__init__.py | 2 + .../components/schema/test_items_schema.py | 25 + .../schema/test_multi_properties_schema.py | 25 + .../codegen/generators/DefaultGenerator.java | 2 +- .../3_0/python/petstore_customized.yaml | 26 +- 19 files changed, 2065 insertions(+), 2 deletions(-) create mode 100644 samples/client/petstore/java/docs/components/schemas/ItemsSchema.md create mode 100644 samples/client/petstore/java/docs/components/schemas/MultiPropertiesSchema.md create mode 100644 samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java create mode 100644 samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchema.java create mode 100644 samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java create mode 100644 samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java create mode 100644 samples/client/petstore/python/docs/components/schema/items_schema.md create mode 100644 samples/client/petstore/python/docs/components/schema/multi_properties_schema.md create mode 100644 samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py create mode 100644 samples/client/petstore/python/src/petstore_api/components/schema/multi_properties_schema.py create mode 100644 samples/client/petstore/python/test/components/schema/test_items_schema.py create mode 100644 samples/client/petstore/python/test/components/schema/test_multi_properties_schema.py diff --git a/samples/client/petstore/java/.openapi-generator/FILES b/samples/client/petstore/java/.openapi-generator/FILES index 75d48d1effe..ca71993fd68 100644 --- a/samples/client/petstore/java/.openapi-generator/FILES +++ b/samples/client/petstore/java/.openapi-generator/FILES @@ -112,6 +112,7 @@ docs/components/schemas/IntegerMax10.md docs/components/schemas/IntegerMin15.md docs/components/schemas/IsoscelesTriangle.md docs/components/schemas/Items.md +docs/components/schemas/ItemsSchema.md docs/components/schemas/JSONPatchRequest.md docs/components/schemas/JSONPatchRequestAddReplaceTest.md docs/components/schemas/JSONPatchRequestMoveCopy.md @@ -120,6 +121,7 @@ docs/components/schemas/Mammal.md docs/components/schemas/MapTest.md docs/components/schemas/MixedPropertiesAndAdditionalPropertiesClass.md docs/components/schemas/Money.md +docs/components/schemas/MultiPropertiesSchema.md docs/components/schemas/MyObjectDto.md docs/components/schemas/Name.md docs/components/schemas/NoAdditionalProperties.md @@ -811,6 +813,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/IntegerMax10. src/main/java/org/openapijsonschematools/client/components/schemas/IntegerMin15.java src/main/java/org/openapijsonschematools/client/components/schemas/IsoscelesTriangle.java src/main/java/org/openapijsonschematools/client/components/schemas/Items.java +src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java src/main/java/org/openapijsonschematools/client/components/schemas/JSONPatchRequest.java src/main/java/org/openapijsonschematools/client/components/schemas/JSONPatchRequestAddReplaceTest.java src/main/java/org/openapijsonschematools/client/components/schemas/JSONPatchRequestMoveCopy.java @@ -819,6 +822,7 @@ src/main/java/org/openapijsonschematools/client/components/schemas/Mammal.java src/main/java/org/openapijsonschematools/client/components/schemas/MapTest.java src/main/java/org/openapijsonschematools/client/components/schemas/MixedPropertiesAndAdditionalPropertiesClass.java src/main/java/org/openapijsonschematools/client/components/schemas/Money.java +src/main/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchema.java src/main/java/org/openapijsonschematools/client/components/schemas/MyObjectDto.java src/main/java/org/openapijsonschematools/client/components/schemas/Name.java src/main/java/org/openapijsonschematools/client/components/schemas/NoAdditionalProperties.java @@ -1695,6 +1699,8 @@ src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java src/main/java/org/openapijsonschematools/client/servers/server0/Variables.java src/main/java/org/openapijsonschematools/client/servers/server1/Variables.java +src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java +src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java src/test/java/org/openapijsonschematools/client/header/ContentHeaderTest.java src/test/java/org/openapijsonschematools/client/header/SchemaHeaderTest.java diff --git a/samples/client/petstore/java/README.md b/samples/client/petstore/java/README.md index 03a9445924d..74b5c37447f 100644 --- a/samples/client/petstore/java/README.md +++ b/samples/client/petstore/java/README.md @@ -222,6 +222,7 @@ allowed input and output types. | [IntegerMin15.IntegerMin151](docs/components/schemas/IntegerMin15.md#integermin151) | | | [IsoscelesTriangle.IsoscelesTriangle1](docs/components/schemas/IsoscelesTriangle.md#isoscelestriangle1) | | | [Items.Items1](docs/components/schemas/Items.md#items1) | component's name collides with the inner schema name | +| [ItemsSchema.ItemsSchema1](docs/components/schemas/ItemsSchema.md#itemsschema1) | | | [JSONPatchRequest.JSONPatchRequest1](docs/components/schemas/JSONPatchRequest.md#jsonpatchrequest1) | | | [JSONPatchRequestAddReplaceTest.JSONPatchRequestAddReplaceTest1](docs/components/schemas/JSONPatchRequestAddReplaceTest.md#jsonpatchrequestaddreplacetest1) | | | [JSONPatchRequestMoveCopy.JSONPatchRequestMoveCopy1](docs/components/schemas/JSONPatchRequestMoveCopy.md#jsonpatchrequestmovecopy1) | | @@ -229,6 +230,7 @@ allowed input and output types. | [MapTest.MapTest1](docs/components/schemas/MapTest.md#maptest1) | | | [MixedPropertiesAndAdditionalPropertiesClass.MixedPropertiesAndAdditionalPropertiesClass1](docs/components/schemas/MixedPropertiesAndAdditionalPropertiesClass.md#mixedpropertiesandadditionalpropertiesclass1) | | | [Money.Money1](docs/components/schemas/Money.md#money1) | | +| [MultiPropertiesSchema.MultiPropertiesSchema1](docs/components/schemas/MultiPropertiesSchema.md#multipropertiesschema1) | | | [MyObjectDto.MyObjectDto1](docs/components/schemas/MyObjectDto.md#myobjectdto1) | | | [Name.Name1](docs/components/schemas/Name.md#name1) | Model for testing model name same as property name | | [NoAdditionalProperties.NoAdditionalProperties1](docs/components/schemas/NoAdditionalProperties.md#noadditionalproperties1) | | diff --git a/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md b/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md new file mode 100644 index 00000000000..3f4e1664e0a --- /dev/null +++ b/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md @@ -0,0 +1,253 @@ +# ItemsSchema +org.openapijsonschematools.client.components.schemas.ItemsSchema.java +public class ItemsSchema
+ +A class that contains necessary nested +- schema classes (which validate payloads), extends JsonSchema +- sealed interfaces which store validated payloads, java version of a sum type +- boxed classes which store validated payloads, sealed permits class implementations +- classes to store validated map payloads, extends FrozenMap +- classes to build inputs for map payloads + +## Nested Class Summary +| Modifier and Type | Class and Description | +| ----------------- | ---------------------- | +| sealed interface | [ItemsSchema.ItemsSchema1Boxed](#itemsschema1boxed)
sealed interface for validated payloads | +| record | [ItemsSchema.ItemsSchema1BoxedMap](#itemsschema1boxedmap)
boxed class to store validated Map payloads | +| static class | [ItemsSchema.ItemsSchema1](#itemsschema1)
schema class | +| static class | [ItemsSchema.ItemsSchemaMapBuilder](#itemsschemamapbuilder)
builder for Map payloads | +| static class | [ItemsSchema.ItemsSchemaMap](#itemsschemamap)
output class for Map payloads | +| sealed interface | [ItemsSchema.SecondAdditionalPropertyBoxed](#secondadditionalpropertyboxed)
sealed interface for validated payloads | +| record | [ItemsSchema.SecondAdditionalPropertyBoxedString](#secondadditionalpropertyboxedstring)
boxed class to store validated String payloads | +| static class | [ItemsSchema.SecondAdditionalProperty](#secondadditionalproperty)
schema class | +| sealed interface | [ItemsSchema.AdditionalPropertyBoxed](#additionalpropertyboxed)
sealed interface for validated payloads | +| record | [ItemsSchema.AdditionalPropertyBoxedString](#additionalpropertyboxedstring)
boxed class to store validated String payloads | +| static class | [ItemsSchema.AdditionalProperty](#additionalproperty)
schema class | +| sealed interface | [ItemsSchema.NameBoxed](#nameboxed)
sealed interface for validated payloads | +| record | [ItemsSchema.NameBoxedString](#nameboxedstring)
boxed class to store validated String payloads | +| static class | [ItemsSchema.Name](#name)
schema class | + +## ItemsSchema1Boxed +public sealed interface ItemsSchema1Boxed
+permits
+[ItemsSchema1BoxedMap](#itemsschema1boxedmap) + +sealed interface that stores validated payloads using boxed classes + +## ItemsSchema1BoxedMap +public record ItemsSchema1BoxedMap
+implements [ItemsSchema1Boxed](#itemsschema1boxed) + +record that stores validated Map payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| ItemsSchema1BoxedMap([ItemsSchemaMap](#itemsschemamap) data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [ItemsSchemaMap](#itemsschemamap) | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## ItemsSchema1 +public static class ItemsSchema1
+extends JsonSchema + +A schema class that validates payloads + +### Code Sample +``` +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.openapijsonschematools.client.schemas.validation.FrozenList; +import org.openapijsonschematools.client.schemas.validation.FrozenMap; +import org.openapijsonschematools.client.components.schemas.ItemsSchema; + +import java.util.Arrays; +import java.util.List; +import java.util.AbstractMap; + +static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build()); + +// Map validation +ItemsSchema.ItemsSchemaMap validatedPayload = + ItemsSchema.ItemsSchema1.validate( + new ItemsSchema.ItemsSchemaMapBuilder() + .name("a") + + .additionalProperty("a") + + .secondAdditionalProperty("a") + + .build(), + configuration +); +``` + +### Field Summary +| Modifier and Type | Field and Description | +| ----------------- | ---------------------- | +| Set> | type = Set.of(Map.class) | +| Map> | properties = Map.ofEntries(
    new PropertyEntry("name", [Name.class](#name))),
    new PropertyEntry("additionalProperty", [AdditionalProperty.class](#additionalproperty))),
    new PropertyEntry("secondAdditionalProperty", [SecondAdditionalProperty.class](#secondadditionalproperty)))
)
| + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [ItemsSchemaMap](#itemsschemamap) | validate([Map<?, ?>](#itemsschemamapbuilder) arg, SchemaConfiguration configuration) | +| [ItemsSchema1BoxedMap](#itemsschema1boxedmap) | validateAndBox([Map<?, ?>](#itemsschemamapbuilder) arg, SchemaConfiguration configuration) | +| [ItemsSchema1Boxed](#itemsschema1boxed) | validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) | +| @Nullable Object | validate(@Nullable Object arg, SchemaConfiguration configuration) | + +## ItemsSchemaMapBuilder +public class ItemsSchemaMapBuilder
+builder for `Map` + +A class that builds the Map input type + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| ItemsSchemaMapBuilder()
Creates a builder that contains an empty map | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| Map | build()
Returns map input that should be used with Schema.validate | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | name(String value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | secondAdditionalProperty(String value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, Void value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, boolean value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, String value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, int value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, float value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, long value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, double value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, List value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, Map value) | + +## ItemsSchemaMap +public static class ItemsSchemaMap
+extends FrozenMap + +A class to store validated Map payloads + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| static [ItemsSchemaMap](#itemsschemamap) | of([Map](#itemsschemamapbuilder) arg, SchemaConfiguration configuration) | +| String | name()
[optional] | +| String | additionalProperty()
[optional] | +| String | secondAdditionalProperty()
[optional] | +| @Nullable Object | getAdditionalProperty(String name)
provides type safety for additional properties | + +## SecondAdditionalPropertyBoxed +public sealed interface SecondAdditionalPropertyBoxed
+permits
+[SecondAdditionalPropertyBoxedString](#secondadditionalpropertyboxedstring) + +sealed interface that stores validated payloads using boxed classes + +## SecondAdditionalPropertyBoxedString +public record SecondAdditionalPropertyBoxedString
+implements [SecondAdditionalPropertyBoxed](#secondadditionalpropertyboxed) + +record that stores validated String payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| SecondAdditionalPropertyBoxedString(String data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| String | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## SecondAdditionalProperty +public static class SecondAdditionalProperty
+extends StringJsonSchema.StringJsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.StringJsonSchema.StringJsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +## AdditionalPropertyBoxed +public sealed interface AdditionalPropertyBoxed
+permits
+[AdditionalPropertyBoxedString](#additionalpropertyboxedstring) + +sealed interface that stores validated payloads using boxed classes + +## AdditionalPropertyBoxedString +public record AdditionalPropertyBoxedString
+implements [AdditionalPropertyBoxed](#additionalpropertyboxed) + +record that stores validated String payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertyBoxedString(String data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| String | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalProperty +public static class AdditionalProperty
+extends StringJsonSchema.StringJsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.StringJsonSchema.StringJsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +## NameBoxed +public sealed interface NameBoxed
+permits
+[NameBoxedString](#nameboxedstring) + +sealed interface that stores validated payloads using boxed classes + +## NameBoxedString +public record NameBoxedString
+implements [NameBoxed](#nameboxed) + +record that stores validated String payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| NameBoxedString(String data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| String | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## Name +public static class Name
+extends StringJsonSchema.StringJsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.StringJsonSchema.StringJsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md) diff --git a/samples/client/petstore/java/docs/components/schemas/MultiPropertiesSchema.md b/samples/client/petstore/java/docs/components/schemas/MultiPropertiesSchema.md new file mode 100644 index 00000000000..7ac0b8013b4 --- /dev/null +++ b/samples/client/petstore/java/docs/components/schemas/MultiPropertiesSchema.md @@ -0,0 +1,463 @@ +# MultiPropertiesSchema +org.openapijsonschematools.client.components.schemas.MultiPropertiesSchema.java +public class MultiPropertiesSchema
+ +A class that contains necessary nested +- schema classes (which validate payloads), extends JsonSchema +- sealed interfaces which store validated payloads, java version of a sum type +- boxed classes which store validated payloads, sealed permits class implementations +- classes to store validated list payloads, extends FrozenList +- classes to build inputs for list payloads +- classes to store validated map payloads, extends FrozenMap +- classes to build inputs for map payloads + +## Nested Class Summary +| Modifier and Type | Class and Description | +| ----------------- | ---------------------- | +| sealed interface | [MultiPropertiesSchema.MultiPropertiesSchema1Boxed](#multipropertiesschema1boxed)
sealed interface for validated payloads | +| record | [MultiPropertiesSchema.MultiPropertiesSchema1BoxedMap](#multipropertiesschema1boxedmap)
boxed class to store validated Map payloads | +| static class | [MultiPropertiesSchema.MultiPropertiesSchema1](#multipropertiesschema1)
schema class | +| static class | [MultiPropertiesSchema.MultiPropertiesSchemaMapBuilder](#multipropertiesschemamapbuilder)
builder for Map payloads | +| static class | [MultiPropertiesSchema.MultiPropertiesSchemaMap](#multipropertiesschemamap)
output class for Map payloads | +| sealed interface | [MultiPropertiesSchema.DataBoxed](#databoxed)
sealed interface for validated payloads | +| record | [MultiPropertiesSchema.DataBoxedList](#databoxedlist)
boxed class to store validated List payloads | +| static class | [MultiPropertiesSchema.Data](#data)
schema class | +| static class | [MultiPropertiesSchema.DataListBuilder](#datalistbuilder)
builder for List payloads | +| static class | [MultiPropertiesSchema.DataList](#datalist)
output class for List payloads | +| sealed interface | [MultiPropertiesSchema.MessageBoxed](#messageboxed)
sealed interface for validated payloads | +| record | [MultiPropertiesSchema.MessageBoxedString](#messageboxedstring)
boxed class to store validated String payloads | +| static class | [MultiPropertiesSchema.Message](#message)
schema class | +| sealed interface | [MultiPropertiesSchema.StatusBoxed](#statusboxed)
sealed interface for validated payloads | +| record | [MultiPropertiesSchema.StatusBoxedNumber](#statusboxednumber)
boxed class to store validated Number payloads | +| static class | [MultiPropertiesSchema.Status](#status)
schema class | +| sealed interface | [MultiPropertiesSchema.AdditionalPropertiesBoxed](#additionalpropertiesboxed)
sealed interface for validated payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedVoid](#additionalpropertiesboxedvoid)
boxed class to store validated null payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedBoolean](#additionalpropertiesboxedboolean)
boxed class to store validated boolean payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedNumber](#additionalpropertiesboxednumber)
boxed class to store validated Number payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedString](#additionalpropertiesboxedstring)
boxed class to store validated String payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedList](#additionalpropertiesboxedlist)
boxed class to store validated List payloads | +| record | [MultiPropertiesSchema.AdditionalPropertiesBoxedMap](#additionalpropertiesboxedmap)
boxed class to store validated Map payloads | +| static class | [MultiPropertiesSchema.AdditionalProperties](#additionalproperties)
schema class | + +## MultiPropertiesSchema1Boxed +public sealed interface MultiPropertiesSchema1Boxed
+permits
+[MultiPropertiesSchema1BoxedMap](#multipropertiesschema1boxedmap) + +sealed interface that stores validated payloads using boxed classes + +## MultiPropertiesSchema1BoxedMap +public record MultiPropertiesSchema1BoxedMap
+implements [MultiPropertiesSchema1Boxed](#multipropertiesschema1boxed) + +record that stores validated Map payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| MultiPropertiesSchema1BoxedMap([MultiPropertiesSchemaMap](#multipropertiesschemamap) data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [MultiPropertiesSchemaMap](#multipropertiesschemamap) | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## MultiPropertiesSchema1 +public static class MultiPropertiesSchema1
+extends JsonSchema + +A schema class that validates payloads + +### Code Sample +``` +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.openapijsonschematools.client.schemas.validation.FrozenList; +import org.openapijsonschematools.client.schemas.validation.FrozenMap; +import org.openapijsonschematools.client.components.schemas.MultiPropertiesSchema; + +import java.util.Arrays; +import java.util.List; +import java.util.AbstractMap; + +static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build()); + +// Map validation +MultiPropertiesSchema.MultiPropertiesSchemaMap validatedPayload = + MultiPropertiesSchema.MultiPropertiesSchema1.validate( + new MultiPropertiesSchema.MultiPropertiesSchemaMapBuilder() + .status(1) + + .data( + Arrays.asList( + ) + ) + .message("a") + + .build(), + configuration +); +``` + +### Field Summary +| Modifier and Type | Field and Description | +| ----------------- | ---------------------- | +| Set> | type = Set.of(Map.class) | +| Map> | properties = Map.ofEntries(
    new PropertyEntry("status", [Status.class](#status))),
    new PropertyEntry("data", [Data.class](#data))),
    new PropertyEntry("message", [Message.class](#message)))
)
| +| Set | required = Set.of(
    "status"
)
| +| Class | additionalProperties = [AdditionalProperties.class](#additionalproperties) | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [MultiPropertiesSchemaMap](#multipropertiesschemamap) | validate([Map<?, ?>](#multipropertiesschemamapbuilder) arg, SchemaConfiguration configuration) | +| [MultiPropertiesSchema1BoxedMap](#multipropertiesschema1boxedmap) | validateAndBox([Map<?, ?>](#multipropertiesschemamapbuilder) arg, SchemaConfiguration configuration) | +| [MultiPropertiesSchema1Boxed](#multipropertiesschema1boxed) | validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) | +| @Nullable Object | validate(@Nullable Object arg, SchemaConfiguration configuration) | + +## MultiPropertiesSchemaMap0Builder +public class MultiPropertiesSchemaMap0Builder
+builder for `Map` + +A class that builds the Map input type + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| MultiPropertiesSchemaMap0Builder(Map instance)
Creates a builder that contains the passed instance | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| Map | build()
Returns map input that should be used with Schema.validate | +| [MultiPropertiesSchemaMap0Builder](#multipropertiesschemamap0builder) | data(List> value) | +| [MultiPropertiesSchemaMap0Builder](#multipropertiesschemamap0builder) | message(String value) | + +## MultiPropertiesSchemaMapBuilder +public class MultiPropertiesSchemaMapBuilder
+builder for `Map` + +A class that builds the Map input type + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| MultiPropertiesSchemaMapBuilder()
Creates a builder that contains an empty map | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [MultiPropertiesSchemaMap0Builder](#multipropertiesschemamap0builder) | status(int value) | +| [MultiPropertiesSchemaMap0Builder](#multipropertiesschemamap0builder) | status(float value) | + +## MultiPropertiesSchemaMap +public static class MultiPropertiesSchemaMap
+extends FrozenMap + +A class to store validated Map payloads + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| static [MultiPropertiesSchemaMap](#multipropertiesschemamap) | of([Map](#multipropertiesschemamapbuilder) arg, SchemaConfiguration configuration) | +| Number | status()
value must be a 32 bit integer | +| [DataList](#datalist) | data()
[optional] | +| String | message()
[optional] | + +## DataBoxed +public sealed interface DataBoxed
+permits
+[DataBoxedList](#databoxedlist) + +sealed interface that stores validated payloads using boxed classes + +## DataBoxedList +public record DataBoxedList
+implements [DataBoxed](#databoxed) + +record that stores validated List payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| DataBoxedList([DataList](#datalist) data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [DataList](#datalist) | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## Data +public static class Data
+extends JsonSchema + +A schema class that validates payloads + +### Code Sample +``` +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.openapijsonschematools.client.schemas.validation.FrozenList; +import org.openapijsonschematools.client.schemas.validation.FrozenMap; +import org.openapijsonschematools.client.components.schemas.MultiPropertiesSchema; + +import java.util.Arrays; +import java.util.List; +import java.util.AbstractMap; + +static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build()); + +// List validation +MultiPropertiesSchema.DataList validatedPayload = + MultiPropertiesSchema.Data.validate( + new MultiPropertiesSchema.DataListBuilder() + .build(), + configuration +); +``` + +### Field Summary +| Modifier and Type | Field and Description | +| ----------------- | ---------------------- | +| Set> | type = Set.of(List.class) | +| Class | items = [ItemsSchema.ItemsSchema1.class](../../components/schemas/ItemsSchema.md#itemsschema1) | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| [DataList](#datalist) | validate([List](#datalistbuilder) arg, SchemaConfiguration configuration) | +| [DataBoxedList](#databoxedlist) | validateAndBox([List](#datalistbuilder) arg, SchemaConfiguration configuration) | +| [DataBoxed](#databoxed) | validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) | +| @Nullable Object | validate(@Nullable Object arg, SchemaConfiguration configuration) | + +## DataListBuilder +public class DataListBuilder
+builder for `List>` + +A class that builds the List input type + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| DataListBuilder()
Creates an empty list | +| DataListBuilder(List> items)
Stores the items in a list | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| DataListBuilder | add(Map item) | +| List> | build()
Returns list input that should be used with Schema.validate | + +## DataList +public class DataList
+extends `FrozenList` + +A class to store validated List payloads + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| static [DataList](#datalist) | of([List>](#datalistbuilder) arg, SchemaConfiguration configuration) | + +## MessageBoxed +public sealed interface MessageBoxed
+permits
+[MessageBoxedString](#messageboxedstring) + +sealed interface that stores validated payloads using boxed classes + +## MessageBoxedString +public record MessageBoxedString
+implements [MessageBoxed](#messageboxed) + +record that stores validated String payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| MessageBoxedString(String data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| String | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## Message +public static class Message
+extends StringJsonSchema.StringJsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.StringJsonSchema.StringJsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +## StatusBoxed +public sealed interface StatusBoxed
+permits
+[StatusBoxedNumber](#statusboxednumber) + +sealed interface that stores validated payloads using boxed classes + +## StatusBoxedNumber +public record StatusBoxedNumber
+implements [StatusBoxed](#statusboxed) + +record that stores validated Number payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| StatusBoxedNumber(Number data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| Number | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## Status +public static class Status
+extends Int32JsonSchema.Int32JsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.Int32JsonSchema.Int32JsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +## AdditionalPropertiesBoxed +public sealed interface AdditionalPropertiesBoxed
+permits
+[AdditionalPropertiesBoxedVoid](#additionalpropertiesboxedvoid), +[AdditionalPropertiesBoxedBoolean](#additionalpropertiesboxedboolean), +[AdditionalPropertiesBoxedNumber](#additionalpropertiesboxednumber), +[AdditionalPropertiesBoxedString](#additionalpropertiesboxedstring), +[AdditionalPropertiesBoxedList](#additionalpropertiesboxedlist), +[AdditionalPropertiesBoxedMap](#additionalpropertiesboxedmap) + +sealed interface that stores validated payloads using boxed classes + +## AdditionalPropertiesBoxedVoid +public record AdditionalPropertiesBoxedVoid
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated null payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedVoid(Void data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| Void | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalPropertiesBoxedBoolean +public record AdditionalPropertiesBoxedBoolean
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated boolean payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedBoolean(boolean data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| boolean | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalPropertiesBoxedNumber +public record AdditionalPropertiesBoxedNumber
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated Number payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedNumber(Number data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| Number | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalPropertiesBoxedString +public record AdditionalPropertiesBoxedString
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated String payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedString(String data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| String | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalPropertiesBoxedList +public record AdditionalPropertiesBoxedList
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated List payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedList(FrozenList<@Nullable Object> data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| FrozenList<@Nullable Object> | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalPropertiesBoxedMap +public record AdditionalPropertiesBoxedMap
+implements [AdditionalPropertiesBoxed](#additionalpropertiesboxed) + +record that stores validated Map payloads, sealed permits implementation + +### Constructor Summary +| Constructor and Description | +| --------------------------- | +| AdditionalPropertiesBoxedMap(FrozenMap<@Nullable Object> data)
Creates an instance, private visibility | + +### Method Summary +| Modifier and Type | Method and Description | +| ----------------- | ---------------------- | +| FrozenMap<@Nullable Object> | data()
validated payload | +| @Nullable Object | getData()
validated payload | + +## AdditionalProperties +public static class AdditionalProperties
+extends NotAnyTypeJsonSchema.NotAnyTypeJsonSchema1 + +A schema class that validates payloads + +| Methods Inherited from class org.openapijsonschematools.client.schemas.NotAnyTypeJsonSchema.NotAnyTypeJsonSchema1 | +| ------------------------------------------------------------------ | +| validate | +| validateAndBox | + +[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md) diff --git a/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java new file mode 100644 index 00000000000..b59c1d65bc9 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java @@ -0,0 +1,282 @@ +package org.openapijsonschematools.client.components.schemas; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.InvalidAdditionalPropertyException; +import org.openapijsonschematools.client.exceptions.UnsetPropertyException; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.GenericBuilder; +import org.openapijsonschematools.client.schemas.StringJsonSchema; +import org.openapijsonschematools.client.schemas.UnsetAddPropsSetter; +import org.openapijsonschematools.client.schemas.validation.FrozenMap; +import org.openapijsonschematools.client.schemas.validation.JsonSchema; +import org.openapijsonschematools.client.schemas.validation.JsonSchemaInfo; +import org.openapijsonschematools.client.schemas.validation.MapSchemaValidator; +import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap; +import org.openapijsonschematools.client.schemas.validation.PropertyEntry; +import org.openapijsonschematools.client.schemas.validation.ValidationMetadata; + +public class ItemsSchema { + // nest classes so all schemas and input/output classes can be public + + + public static class Name extends StringJsonSchema.StringJsonSchema1 { + private static @Nullable Name instance = null; + public static Name getInstance() { + if (instance == null) { + instance = new Name(); + } + return instance; + } + } + + + public static class AdditionalProperty extends StringJsonSchema.StringJsonSchema1 { + private static @Nullable AdditionalProperty instance = null; + public static AdditionalProperty getInstance() { + if (instance == null) { + instance = new AdditionalProperty(); + } + return instance; + } + } + + + public static class SecondAdditionalProperty extends StringJsonSchema.StringJsonSchema1 { + private static @Nullable SecondAdditionalProperty instance = null; + public static SecondAdditionalProperty getInstance() { + if (instance == null) { + instance = new SecondAdditionalProperty(); + } + return instance; + } + } + + + public static class ItemsSchemaMap extends FrozenMap<@Nullable Object> { + protected ItemsSchemaMap(FrozenMap<@Nullable Object> m) { + super(m); + } + public static final Set requiredKeys = Set.of(); + public static final Set optionalKeys = Set.of( + "name", + "additionalProperty", + "secondAdditionalProperty" + ); + public static ItemsSchemaMap of(Map arg, SchemaConfiguration configuration) throws ValidationException { + return ItemsSchema1.getInstance().validate(arg, configuration); + } + + public String name() throws UnsetPropertyException { + String key = "name"; + throwIfKeyNotPresent(key); + @Nullable Object value = get(key); + if (!(value instanceof String)) { + throw new RuntimeException("Invalid value stored for name"); + } + return (String) value; + } + + public String additionalProperty() throws UnsetPropertyException { + String key = "additionalProperty"; + throwIfKeyNotPresent(key); + @Nullable Object value = get(key); + if (!(value instanceof String)) { + throw new RuntimeException("Invalid value stored for additionalProperty"); + } + return (String) value; + } + + public String secondAdditionalProperty() throws UnsetPropertyException { + String key = "secondAdditionalProperty"; + throwIfKeyNotPresent(key); + @Nullable Object value = get(key); + if (!(value instanceof String)) { + throw new RuntimeException("Invalid value stored for secondAdditionalProperty"); + } + return (String) value; + } + + public @Nullable Object getAdditionalProperty(String name) throws UnsetPropertyException, InvalidAdditionalPropertyException { + throwIfKeyKnown(name, requiredKeys, optionalKeys); + throwIfKeyNotPresent(name); + return get(name); + } + } + + public interface SetterForName { + Map getInstance(); + T getBuilderAfterName(Map instance); + + default T name(String value) { + var instance = getInstance(); + instance.put("name", value); + return getBuilderAfterName(instance); + } + } + + public interface SetterForAdditionalProperty { + Map getInstance(); + T getBuilderAfterAdditionalProperty(Map instance); + + default T additionalProperty(String value) { + var instance = getInstance(); + instance.put("additionalProperty", value); + return getBuilderAfterAdditionalProperty(instance); + } + } + + public interface SetterForSecondAdditionalProperty { + Map getInstance(); + T getBuilderAfterSecondAdditionalProperty(Map instance); + + default T secondAdditionalProperty(String value) { + var instance = getInstance(); + instance.put("secondAdditionalProperty", value); + return getBuilderAfterSecondAdditionalProperty(instance); + } + } + + public static class ItemsSchemaMapBuilder extends UnsetAddPropsSetter implements GenericBuilder>, SetterForName, SetterForAdditionalProperty, SetterForSecondAdditionalProperty { + private final Map instance; + private static final Set knownKeys = Set.of( + "name", + "additionalProperty", + "secondAdditionalProperty" + ); + public Set getKnownKeys() { + return knownKeys; + } + public ItemsSchemaMapBuilder() { + this.instance = new LinkedHashMap<>(); + } + public Map build() { + return instance; + } + public Map getInstance() { + return instance; + } + public ItemsSchemaMapBuilder getBuilderAfterName(Map instance) { + return this; + } + public ItemsSchemaMapBuilder getBuilderAfterAdditionalProperty(Map instance) { + return this; + } + public ItemsSchemaMapBuilder getBuilderAfterSecondAdditionalProperty(Map instance) { + return this; + } + public ItemsSchemaMapBuilder getBuilderAfterAdditionalProperty(Map instance) { + return this; + } + } + + + public sealed interface ItemsSchema1Boxed permits ItemsSchema1BoxedMap { + @Nullable Object getData(); + } + + public record ItemsSchema1BoxedMap(ItemsSchemaMap data) implements ItemsSchema1Boxed { + @Override + public @Nullable Object getData() { + return data; + } + } + + + public static class ItemsSchema1 extends JsonSchema implements MapSchemaValidator { + /* + NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + */ + private static @Nullable ItemsSchema1 instance = null; + + protected ItemsSchema1() { + super(new JsonSchemaInfo() + .type(Set.of(Map.class)) + .properties(Map.ofEntries( + new PropertyEntry("name", Name.class), + new PropertyEntry("additionalProperty", AdditionalProperty.class), + new PropertyEntry("secondAdditionalProperty", SecondAdditionalProperty.class) + )) + ); + } + + public static ItemsSchema1 getInstance() { + if (instance == null) { + instance = new ItemsSchema1(); + } + return instance; + } + + public ItemsSchemaMap getNewInstance(Map arg, List pathToItem, PathToSchemasMap pathToSchemas) { + LinkedHashMap properties = new LinkedHashMap<>(); + for(Map.Entry entry: arg.entrySet()) { + @Nullable Object entryKey = entry.getKey(); + if (!(entryKey instanceof String)) { + throw new RuntimeException("Invalid non-string key value"); + } + String propertyName = (String) entryKey; + List propertyPathToItem = new ArrayList<>(pathToItem); + propertyPathToItem.add(propertyName); + Object value = entry.getValue(); + LinkedHashMap, Void> schemas = pathToSchemas.get(propertyPathToItem); + if (schemas == null) { + throw new RuntimeException("Validation result is invalid, schemas must exist for a pathToItem"); + } + JsonSchema propertySchema = schemas.entrySet().iterator().next().getKey(); + @Nullable Object propertyInstance = propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas); + properties.put(propertyName, propertyInstance); + } + FrozenMap<@Nullable Object> castProperties = new FrozenMap<>(properties); + return new ItemsSchemaMap(castProperties); + } + + public ItemsSchemaMap validate(Map arg, SchemaConfiguration configuration) throws ValidationException { + Set> pathSet = new HashSet<>(); + List pathToItem = List.of("args[0"); + Map castArg = castToAllowedTypes(arg, pathToItem, pathSet); + SchemaConfiguration usedConfiguration = Objects.requireNonNullElseGet(configuration, () -> new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build())); + ValidationMetadata validationMetadata = new ValidationMetadata(pathToItem, usedConfiguration, new PathToSchemasMap(), new LinkedHashSet<>()); + PathToSchemasMap pathToSchemasMap = getPathToSchemas(this, castArg, validationMetadata, pathSet); + return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap); + } + + + @Override + public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof Map) { + return validate((Map) arg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + @Override + public @Nullable Object getNewInstance(@Nullable Object arg, List pathToItem, PathToSchemasMap pathToSchemas) { + if (arg instanceof Map) { + return getNewInstance((Map) arg, pathToItem, pathToSchemas); + } + throw new RuntimeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema"); + } + @Override + public ItemsSchema1BoxedMap validateAndBox(Map arg, SchemaConfiguration configuration) throws ValidationException { + return new ItemsSchema1BoxedMap(validate(arg, configuration)); + } + @Override + public ItemsSchema1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof Map castArg) { + return validateAndBox(castArg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + } + +} diff --git a/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchema.java b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchema.java new file mode 100644 index 00000000000..b8ebf95ee51 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchema.java @@ -0,0 +1,422 @@ +package org.openapijsonschematools.client.components.schemas; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.UnsetPropertyException; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.AnyTypeJsonSchema; +import org.openapijsonschematools.client.schemas.GenericBuilder; +import org.openapijsonschematools.client.schemas.Int32JsonSchema; +import org.openapijsonschematools.client.schemas.NotAnyTypeJsonSchema; +import org.openapijsonschematools.client.schemas.StringJsonSchema; +import org.openapijsonschematools.client.schemas.validation.FrozenList; +import org.openapijsonschematools.client.schemas.validation.FrozenMap; +import org.openapijsonschematools.client.schemas.validation.JsonSchema; +import org.openapijsonschematools.client.schemas.validation.JsonSchemaInfo; +import org.openapijsonschematools.client.schemas.validation.ListSchemaValidator; +import org.openapijsonschematools.client.schemas.validation.MapSchemaValidator; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap; +import org.openapijsonschematools.client.schemas.validation.PropertyEntry; +import org.openapijsonschematools.client.schemas.validation.ValidationMetadata; + +public class MultiPropertiesSchema { + // nest classes so all schemas and input/output classes can be public + + + public static class AdditionalProperties extends NotAnyTypeJsonSchema.NotAnyTypeJsonSchema1 { + // NotAnyTypeSchema + private static @Nullable AdditionalProperties instance = null; + public static AdditionalProperties getInstance() { + if (instance == null) { + instance = new AdditionalProperties(); + } + return instance; + } + } + + + public static class Status extends Int32JsonSchema.Int32JsonSchema1 { + private static @Nullable Status instance = null; + public static Status getInstance() { + if (instance == null) { + instance = new Status(); + } + return instance; + } + } + + + public static class Message extends StringJsonSchema.StringJsonSchema1 { + private static @Nullable Message instance = null; + public static Message getInstance() { + if (instance == null) { + instance = new Message(); + } + return instance; + } + } + + + public static class DataList extends FrozenList { + protected DataList(FrozenList m) { + super(m); + } + public static DataList of(List> arg, SchemaConfiguration configuration) throws ValidationException { + return Data.getInstance().validate(arg, configuration); + } + } + + public static class DataListBuilder { + // class to build List> + private final List> list; + + public DataListBuilder() { + list = new ArrayList<>(); + } + + public DataListBuilder(List> list) { + this.list = list; + } + + public DataListBuilder add(Map item) { + list.add(item); + return this; + } + + public List> build() { + return list; + } + } + + + public sealed interface DataBoxed permits DataBoxedList { + @Nullable Object getData(); + } + + public record DataBoxedList(DataList data) implements DataBoxed { + @Override + public @Nullable Object getData() { + return data; + } + } + + + + public static class Data extends JsonSchema implements ListSchemaValidator { + private static @Nullable Data instance = null; + + protected Data() { + super(new JsonSchemaInfo() + .type(Set.of(List.class)) + .items(ItemsSchema.ItemsSchema1.class) + ); + } + + public static Data getInstance() { + if (instance == null) { + instance = new Data(); + } + return instance; + } + + @Override + public DataList getNewInstance(List arg, List pathToItem, PathToSchemasMap pathToSchemas) { + List items = new ArrayList<>(); + int i = 0; + for (Object item: arg) { + List itemPathToItem = new ArrayList<>(pathToItem); + itemPathToItem.add(i); + LinkedHashMap, Void> schemas = pathToSchemas.get(itemPathToItem); + if (schemas == null) { + throw new RuntimeException("Validation result is invalid, schemas must exist for a pathToItem"); + } + JsonSchema itemSchema = schemas.entrySet().iterator().next().getKey(); + @Nullable Object itemInstance = itemSchema.getNewInstance(item, itemPathToItem, pathToSchemas); + if (!(itemInstance instanceof ItemsSchema.ItemsSchemaMap)) { + throw new RuntimeException("Invalid instantiated value"); + } + items.add((ItemsSchema.ItemsSchemaMap) itemInstance); + i += 1; + } + FrozenList newInstanceItems = new FrozenList<>(items); + return new DataList(newInstanceItems); + } + + public DataList validate(List arg, SchemaConfiguration configuration) throws ValidationException { + Set> pathSet = new HashSet<>(); + List pathToItem = List.of("args[0"); + List castArg = castToAllowedTypes(arg, pathToItem, pathSet); + SchemaConfiguration usedConfiguration = Objects.requireNonNullElseGet(configuration, () -> new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build())); + ValidationMetadata validationMetadata = new ValidationMetadata(pathToItem, usedConfiguration, new PathToSchemasMap(), new LinkedHashSet<>()); + PathToSchemasMap pathToSchemasMap = getPathToSchemas(this, castArg, validationMetadata, pathSet); + return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap); + } + + @Override + public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof List) { + return validate((List) arg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + @Override + public @Nullable Object getNewInstance(@Nullable Object arg, List pathToItem, PathToSchemasMap pathToSchemas) { + if (arg instanceof List) { + return getNewInstance((List) arg, pathToItem, pathToSchemas); + } + throw new RuntimeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema"); + } + @Override + public DataBoxedList validateAndBox(List arg, SchemaConfiguration configuration) throws ValidationException { + return new DataBoxedList(validate(arg, configuration)); + } + @Override + public DataBoxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof List castArg) { + return validateAndBox(castArg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + } + + public static class MultiPropertiesSchemaMap extends FrozenMap { + protected MultiPropertiesSchemaMap(FrozenMap m) { + super(m); + } + public static final Set requiredKeys = Set.of( + "status" + ); + public static final Set optionalKeys = Set.of( + "data", + "message" + ); + public static MultiPropertiesSchemaMap of(Map arg, SchemaConfiguration configuration) throws ValidationException { + return MultiPropertiesSchema1.getInstance().validate(arg, configuration); + } + + public Number status() { + Object value = get("status"); + if (!(value instanceof Number)) { + throw new RuntimeException("Invalid value stored for status"); + } + return (Number) value; + } + + public DataList data() throws UnsetPropertyException { + String key = "data"; + throwIfKeyNotPresent(key); + Object value = get(key); + if (!(value instanceof DataList)) { + throw new RuntimeException("Invalid value stored for data"); + } + return (DataList) value; + } + + public String message() throws UnsetPropertyException { + String key = "message"; + throwIfKeyNotPresent(key); + Object value = get(key); + if (!(value instanceof String)) { + throw new RuntimeException("Invalid value stored for message"); + } + return (String) value; + } + } + + public interface SetterForStatus { + Map getInstance(); + T getBuilderAfterStatus(Map instance); + + default T status(int value) { + var instance = getInstance(); + instance.put("status", value); + return getBuilderAfterStatus(instance); + } + + default T status(float value) { + var instance = getInstance(); + instance.put("status", value); + return getBuilderAfterStatus(instance); + } + } + + public interface SetterForData { + Map getInstance(); + T getBuilderAfterData(Map instance); + + default T data(List> value) { + var instance = getInstance(); + instance.put("data", value); + return getBuilderAfterData(instance); + } + } + + public interface SetterForMessage { + Map getInstance(); + T getBuilderAfterMessage(Map instance); + + default T message(String value) { + var instance = getInstance(); + instance.put("message", value); + return getBuilderAfterMessage(instance); + } + } + + public static class MultiPropertiesSchemaMap0Builder implements GenericBuilder>, SetterForData, SetterForMessage { + private final Map instance; + private static final Set knownKeys = Set.of( + "status", + "data", + "message" + ); + public Set getKnownKeys() { + return knownKeys; + } + public MultiPropertiesSchemaMap0Builder(Map instance) { + this.instance = instance; + } + public Map build() { + return instance; + } + public Map getInstance() { + return instance; + } + public MultiPropertiesSchemaMap0Builder getBuilderAfterData(Map instance) { + return this; + } + public MultiPropertiesSchemaMap0Builder getBuilderAfterMessage(Map instance) { + return this; + } + } + + public static class MultiPropertiesSchemaMapBuilder implements SetterForStatus { + private final Map instance; + public MultiPropertiesSchemaMapBuilder() { + this.instance = new LinkedHashMap<>(); + } + public Map getInstance() { + return instance; + } + public MultiPropertiesSchemaMap0Builder getBuilderAfterStatus(Map instance) { + return new MultiPropertiesSchemaMap0Builder(instance); + } + } + + + public sealed interface MultiPropertiesSchema1Boxed permits MultiPropertiesSchema1BoxedMap { + @Nullable Object getData(); + } + + public record MultiPropertiesSchema1BoxedMap(MultiPropertiesSchemaMap data) implements MultiPropertiesSchema1Boxed { + @Override + public @Nullable Object getData() { + return data; + } + } + + + public static class MultiPropertiesSchema1 extends JsonSchema implements MapSchemaValidator { + /* + NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + */ + private static @Nullable MultiPropertiesSchema1 instance = null; + + protected MultiPropertiesSchema1() { + super(new JsonSchemaInfo() + .type(Set.of(Map.class)) + .properties(Map.ofEntries( + new PropertyEntry("status", Status.class), + new PropertyEntry("data", Data.class), + new PropertyEntry("message", Message.class) + )) + .required(Set.of( + "status" + )) + .additionalProperties(AdditionalProperties.class) + ); + } + + public static MultiPropertiesSchema1 getInstance() { + if (instance == null) { + instance = new MultiPropertiesSchema1(); + } + return instance; + } + + public MultiPropertiesSchemaMap getNewInstance(Map arg, List pathToItem, PathToSchemasMap pathToSchemas) { + LinkedHashMap properties = new LinkedHashMap<>(); + for(Map.Entry entry: arg.entrySet()) { + @Nullable Object entryKey = entry.getKey(); + if (!(entryKey instanceof String)) { + throw new RuntimeException("Invalid non-string key value"); + } + String propertyName = (String) entryKey; + List propertyPathToItem = new ArrayList<>(pathToItem); + propertyPathToItem.add(propertyName); + Object value = entry.getValue(); + LinkedHashMap, Void> schemas = pathToSchemas.get(propertyPathToItem); + if (schemas == null) { + throw new RuntimeException("Validation result is invalid, schemas must exist for a pathToItem"); + } + JsonSchema propertySchema = schemas.entrySet().iterator().next().getKey(); + @Nullable Object propertyInstance = propertySchema.getNewInstance(value, propertyPathToItem, pathToSchemas); + if (!(propertyInstance instanceof Object)) { + throw new RuntimeException("Invalid instantiated value"); + } + properties.put(propertyName, (Object) propertyInstance); + } + FrozenMap castProperties = new FrozenMap<>(properties); + return new MultiPropertiesSchemaMap(castProperties); + } + + public MultiPropertiesSchemaMap validate(Map arg, SchemaConfiguration configuration) throws ValidationException { + Set> pathSet = new HashSet<>(); + List pathToItem = List.of("args[0"); + Map castArg = castToAllowedTypes(arg, pathToItem, pathSet); + SchemaConfiguration usedConfiguration = Objects.requireNonNullElseGet(configuration, () -> new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build())); + ValidationMetadata validationMetadata = new ValidationMetadata(pathToItem, usedConfiguration, new PathToSchemasMap(), new LinkedHashSet<>()); + PathToSchemasMap pathToSchemasMap = getPathToSchemas(this, castArg, validationMetadata, pathSet); + return getNewInstance(castArg, validationMetadata.pathToItem(), pathToSchemasMap); + } + + + @Override + public @Nullable Object validate(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof Map) { + return validate((Map) arg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + @Override + public @Nullable Object getNewInstance(@Nullable Object arg, List pathToItem, PathToSchemasMap pathToSchemas) { + if (arg instanceof Map) { + return getNewInstance((Map) arg, pathToItem, pathToSchemas); + } + throw new RuntimeException("Invalid input type="+getClass(arg)+". It can't be instantiated by this schema"); + } + @Override + public MultiPropertiesSchema1BoxedMap validateAndBox(Map arg, SchemaConfiguration configuration) throws ValidationException { + return new MultiPropertiesSchema1BoxedMap(validate(arg, configuration)); + } + @Override + public MultiPropertiesSchema1Boxed validateAndBox(@Nullable Object arg, SchemaConfiguration configuration) throws ValidationException { + if (arg instanceof Map castArg) { + return validateAndBox(castArg, configuration); + } + throw new ValidationException("Invalid input type="+getClass(arg)+". It can't be validated by this schema"); + } + } + +} diff --git a/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java b/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java new file mode 100644 index 00000000000..e75838f4e6a --- /dev/null +++ b/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java @@ -0,0 +1,18 @@ +package org.openapijsonschematools.client.components.schemas; + +import org.junit.Assert; +import org.junit.Test; +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.AbstractMap; + +public class ItemsSchemaTest { + static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().format().build()); +} diff --git a/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java b/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java new file mode 100644 index 00000000000..d838324a427 --- /dev/null +++ b/samples/client/petstore/java/src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java @@ -0,0 +1,18 @@ +package org.openapijsonschematools.client.components.schemas; + +import org.junit.Assert; +import org.junit.Test; +import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags; +import org.openapijsonschematools.client.configurations.SchemaConfiguration; +import org.openapijsonschematools.client.exceptions.ValidationException; +import org.openapijsonschematools.client.schemas.validation.MapUtils; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.AbstractMap; + +public class MultiPropertiesSchemaTest { + static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().format().build()); +} diff --git a/samples/client/petstore/python/.openapi-generator/FILES b/samples/client/petstore/python/.openapi-generator/FILES index 9634271e7cc..1a383c7c6d8 100644 --- a/samples/client/petstore/python/.openapi-generator/FILES +++ b/samples/client/petstore/python/.openapi-generator/FILES @@ -123,6 +123,7 @@ docs/components/schema/integer_max10.md docs/components/schema/integer_min15.md docs/components/schema/isosceles_triangle.md docs/components/schema/items.md +docs/components/schema/items_schema.md docs/components/schema/json_patch_request.md docs/components/schema/json_patch_request_add_replace_test.md docs/components/schema/json_patch_request_move_copy.md @@ -131,6 +132,7 @@ docs/components/schema/mammal.md docs/components/schema/map_test.md docs/components/schema/mixed_properties_and_additional_properties_class.md docs/components/schema/money.md +docs/components/schema/multi_properties_schema.md docs/components/schema/my_object_dto.md docs/components/schema/name.md docs/components/schema/no_additional_properties.md @@ -642,6 +644,7 @@ src/petstore_api/components/schema/integer_max10.py src/petstore_api/components/schema/integer_min15.py src/petstore_api/components/schema/isosceles_triangle.py src/petstore_api/components/schema/items.py +src/petstore_api/components/schema/items_schema.py src/petstore_api/components/schema/json_patch_request.py src/petstore_api/components/schema/json_patch_request_add_replace_test.py src/petstore_api/components/schema/json_patch_request_move_copy.py @@ -650,6 +653,7 @@ src/petstore_api/components/schema/mammal.py src/petstore_api/components/schema/map_test.py src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py src/petstore_api/components/schema/money.py +src/petstore_api/components/schema/multi_properties_schema.py src/petstore_api/components/schema/my_object_dto.py src/petstore_api/components/schema/name.py src/petstore_api/components/schema/no_additional_properties.py diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index ff87203e5d4..05343fc6df8 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -305,6 +305,7 @@ Class | Description [IntegerMin15](docs/components/schema/integer_min15.md) | [IsoscelesTriangle](docs/components/schema/isosceles_triangle.md) | [Items](docs/components/schema/items.md) | component's name collides with the inner schema name +[ItemsSchema](docs/components/schema/items_schema.md) | [JSONPatchRequest](docs/components/schema/json_patch_request.md) | [JSONPatchRequestAddReplaceTest](docs/components/schema/json_patch_request_add_replace_test.md) | [JSONPatchRequestMoveCopy](docs/components/schema/json_patch_request_move_copy.md) | @@ -312,6 +313,7 @@ Class | Description [MapTest](docs/components/schema/map_test.md) | [MixedPropertiesAndAdditionalPropertiesClass](docs/components/schema/mixed_properties_and_additional_properties_class.md) | [Money](docs/components/schema/money.md) | +[MultiPropertiesSchema](docs/components/schema/multi_properties_schema.md) | [MyObjectDto](docs/components/schema/my_object_dto.md) | [Name](docs/components/schema/name.md) | Model for testing model name same as property name [NoAdditionalProperties](docs/components/schema/no_additional_properties.md) | diff --git a/samples/client/petstore/python/docs/components/schema/items_schema.md b/samples/client/petstore/python/docs/components/schema/items_schema.md new file mode 100644 index 00000000000..3337064f785 --- /dev/null +++ b/samples/client/petstore/python/docs/components/schema/items_schema.md @@ -0,0 +1,49 @@ +# ItemsSchema +petstore_api.components.schema.items_schema +``` +type: schemas.Schema +``` + +## validate method +Input Type | Return Type | Notes +------------ | ------------- | ------------- +[ItemsSchemaDictInput](#itemsschemadictinput), [ItemsSchemaDict](#itemsschemadict) | [ItemsSchemaDict](#itemsschemadict) | + +## ItemsSchemaDictInput +``` +type: typing.Mapping[str, schemas.INPUT_TYPES_ALL] +``` +Key | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | str | | [optional] +**additionalProperty** | str | | [optional] +**secondAdditionalProperty** | str | | [optional] +**any_string_name** | dict, schemas.immutabledict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] + +## ItemsSchemaDict +``` +base class: schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES] + +``` +### __new__ method +Keyword Argument | Type | Description | Notes +---------------- | ---- | ----------- | ----- +**name** | str, schemas.Unset | | [optional] +**additionalProperty** | str, schemas.Unset | | [optional] +**secondAdditionalProperty** | str, schemas.Unset | | [optional] +**kwargs** | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] typed value is accessed with the get_additional_property_ method + +### properties +Property | Type | Description | Notes +-------- | ---- | ----------- | ----- +**name** | str, schemas.Unset | | [optional] +**additionalProperty** | str, schemas.Unset | | [optional] +**secondAdditionalProperty** | str, schemas.Unset | | [optional] + +### methods +Method | Input Type | Return Type | Notes +------ | ---------- | ----------- | ------ +from_dict_ | [ItemsSchemaDictInput](#itemsschemadictinput), [ItemsSchemaDict](#itemsschemadict) | [ItemsSchemaDict](#itemsschemadict) | a constructor +get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset | provides type safety for additional properties + +[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md) diff --git a/samples/client/petstore/python/docs/components/schema/multi_properties_schema.md b/samples/client/petstore/python/docs/components/schema/multi_properties_schema.md new file mode 100644 index 00000000000..30e17c80ac0 --- /dev/null +++ b/samples/client/petstore/python/docs/components/schema/multi_properties_schema.md @@ -0,0 +1,100 @@ +# MultiPropertiesSchema +petstore_api.components.schema.multi_properties_schema +``` +type: schemas.Schema +``` + +## validate method +Input Type | Return Type | Notes +------------ | ------------- | ------------- +[MultiPropertiesSchemaDictInput](#multipropertiesschemadictinput), [MultiPropertiesSchemaDict](#multipropertiesschemadict) | [MultiPropertiesSchemaDict](#multipropertiesschemadict) | + +## MultiPropertiesSchemaDictInput +``` +type: typing.TypedDict +``` +Key | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**status** | int | | value must be a 32 bit integer +**data** | [DataTupleInput](#datatupleinput), [DataTuple](#datatuple) | | [optional] +**message** | str | | [optional] + +## MultiPropertiesSchemaDict +``` +base class: schemas.immutabledict[str, typing.Union[ + str, + typing.Tuple[schemas.OUTPUT_BASE_TYPES], + int, +]] + +``` +### __new__ method +Keyword Argument | Type | Description | Notes +---------------- | ---- | ----------- | ----- +**status** | int | | value must be a 32 bit integer +**data** | [DataTupleInput](#datatupleinput), [DataTuple](#datatuple), schemas.Unset | | [optional] +**message** | str, schemas.Unset | | [optional] + +### properties +Property | Type | Description | Notes +-------- | ---- | ----------- | ----- +**status** | int | | value must be a 32 bit integer +**data** | [DataTuple](#datatuple), schemas.Unset | | [optional] +**message** | str, schemas.Unset | | [optional] + +### methods +Method | Input Type | Return Type | Notes +------ | ---------- | ----------- | ------ +from_dict_ | [MultiPropertiesSchemaDictInput](#multipropertiesschemadictinput), [MultiPropertiesSchemaDict](#multipropertiesschemadict) | [MultiPropertiesSchemaDict](#multipropertiesschemadict) | a constructor + +# Data +``` +type: schemas.Schema +``` + +## validate method +Input Type | Return Type | Notes +------------ | ------------- | ------------- +[DataTupleInput](#datatupleinput), [DataTuple](#datatuple) | [DataTuple](#datatuple) | + +## DataTupleInput +``` +type: typing.Union[ + typing.List[ + typing.Union[ + items_schema.ItemsSchemaDictInput, + items_schema.ItemsSchemaDict, + ], + ], + typing.Tuple[ + typing.Union[ + items_schema.ItemsSchemaDictInput, + items_schema.ItemsSchemaDict, + ], + ... + ] +] +``` +List/Tuple Item Type | Description | Notes +-------------------- | ------------- | ------------- +[items_schema.ItemsSchemaDictInput](../../components/schema/items_schema.md#itemsschemadictinput), [items_schema.ItemsSchemaDict](../../components/schema/items_schema.md#itemsschemadict) | | + +## DataTuple +``` +base class: typing.Tuple[ + items_schema.ItemsSchemaDict, + ... +] +``` +### __new__ method +Argument | Type +-------- | ------ +arg | [DataTupleInput](#datatupleinput), [DataTuple](#datatuple) +configuration | typing.Optional[schema_configuration.SchemaConfiguration] = None + +### methods +Method | Input Type | Return Type | Notes +------ | ---------- | ----------- | ------ +__getitem__ | int | [items_schema.ItemsSchemaDict](../../components/schema/items_schema.md#itemsschemadict) | This method is used under the hood when instance[0] is called + +[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md) diff --git a/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py b/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py new file mode 100644 index 00000000000..dd1fbbb4dfc --- /dev/null +++ b/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py @@ -0,0 +1,146 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. # noqa: E501 + The version of the OpenAPI document: 1.0.0 + Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator +""" + +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary] + +Name: typing_extensions.TypeAlias = schemas.StrSchema +AdditionalProperty: typing_extensions.TypeAlias = schemas.StrSchema +SecondAdditionalProperty: typing_extensions.TypeAlias = schemas.StrSchema +Properties = typing.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + "additionalProperty": typing.Type[AdditionalProperty], + "secondAdditionalProperty": typing.Type[SecondAdditionalProperty], + } +) + + +class ItemsSchemaDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]): + + __required_keys__: typing.FrozenSet[str] = frozenset({ + }) + __optional_keys__: typing.FrozenSet[str] = frozenset({ + "name", + "additionalProperty", + "secondAdditionalProperty", + }) + + def __new__( + cls, + *, + name: typing.Union[ + str, + schemas.Unset + ] = schemas.unset, + additionalProperty: typing.Union[ + str, + schemas.Unset + ] = schemas.unset, + secondAdditionalProperty: typing.Union[ + str, + schemas.Unset + ] = schemas.unset, + configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL, + ): + arg_: typing.Dict[str, typing.Any] = {} + for key_, val in ( + ("name", name), + ("additionalProperty", additionalProperty), + ("secondAdditionalProperty", secondAdditionalProperty), + ): + if isinstance(val, schemas.Unset): + continue + arg_[key_] = val + arg_.update(kwargs) + used_arg_ = typing.cast(ItemsSchemaDictInput, arg_) + return ItemsSchema.validate(used_arg_, configuration=configuration_) + + @staticmethod + def from_dict_( + arg: typing.Union[ + ItemsSchemaDictInput, + ItemsSchemaDict + ], + configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None + ) -> ItemsSchemaDict: + return ItemsSchema.validate(arg, configuration=configuration) + + @property + def name(self) -> typing.Union[str, schemas.Unset]: + val = self.get("name", schemas.unset) + if isinstance(val, schemas.Unset): + return val + return typing.cast( + str, + val + ) + + @property + def additionalProperty(self) -> typing.Union[str, schemas.Unset]: + val = self.get("additionalProperty", schemas.unset) + if isinstance(val, schemas.Unset): + return val + return typing.cast( + str, + val + ) + + @property + def secondAdditionalProperty(self) -> typing.Union[str, schemas.Unset]: + val = self.get("secondAdditionalProperty", schemas.unset) + if isinstance(val, schemas.Unset): + return val + return typing.cast( + str, + val + ) + + def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]: + schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__) + return self.get(name, schemas.unset) +ItemsSchemaDictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL] + + +@dataclasses.dataclass(frozen=True) +class ItemsSchema( + schemas.Schema[ItemsSchemaDict, tuple] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + types: typing.FrozenSet[typing.Type] = frozenset({schemas.immutabledict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + type_to_output_cls: typing.Mapping[ + typing.Type, + typing.Type + ] = dataclasses.field( + default_factory=lambda: { + schemas.immutabledict: ItemsSchemaDict + } + ) + + @classmethod + def validate( + cls, + arg: typing.Union[ + ItemsSchemaDictInput, + ItemsSchemaDict, + ], + configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None + ) -> ItemsSchemaDict: + return super().validate_base( + arg, + configuration=configuration, + ) + diff --git a/samples/client/petstore/python/src/petstore_api/components/schema/multi_properties_schema.py b/samples/client/petstore/python/src/petstore_api/components/schema/multi_properties_schema.py new file mode 100644 index 00000000000..529bcf91206 --- /dev/null +++ b/samples/client/petstore/python/src/petstore_api/components/schema/multi_properties_schema.py @@ -0,0 +1,222 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. # noqa: E501 + The version of the OpenAPI document: 1.0.0 + Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator +""" + +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary] + +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema +Status: typing_extensions.TypeAlias = schemas.Int32Schema +Message: typing_extensions.TypeAlias = schemas.StrSchema +MultiPropertiesSchemaRequiredDictInput = typing.TypedDict( + 'MultiPropertiesSchemaRequiredDictInput', + { + "status": int, + } +) + +from petstore_api.components.schema import items_schema + + +class DataTuple( + typing.Tuple[ + items_schema.ItemsSchemaDict, + ... + ] +): + + def __new__(cls, arg: typing.Union[DataTupleInput, DataTuple], configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None): + return Data.validate(arg, configuration=configuration) +DataTupleInput = typing.Union[ + typing.List[ + typing.Union[ + items_schema.ItemsSchemaDictInput, + items_schema.ItemsSchemaDict, + ], + ], + typing.Tuple[ + typing.Union[ + items_schema.ItemsSchemaDictInput, + items_schema.ItemsSchemaDict, + ], + ... + ] +] + + +@dataclasses.dataclass(frozen=True) +class Data( + schemas.Schema[schemas.immutabledict, DataTuple] +): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[items_schema.ItemsSchema] = dataclasses.field(default_factory=lambda: items_schema.ItemsSchema) # type: ignore + type_to_output_cls: typing.Mapping[ + typing.Type, + typing.Type + ] = dataclasses.field( + default_factory=lambda: { + tuple: DataTuple + } + ) + + @classmethod + def validate( + cls, + arg: typing.Union[ + DataTupleInput, + DataTuple, + ], + configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None + ) -> DataTuple: + return super().validate_base( + arg, + configuration=configuration, + ) +Properties = typing.TypedDict( + 'Properties', + { + "status": typing.Type[Status], + "data": typing.Type[Data], + "message": typing.Type[Message], + } +) +MultiPropertiesSchemaOptionalDictInput = typing.TypedDict( + 'MultiPropertiesSchemaOptionalDictInput', + { + "data": typing.Union[ + DataTupleInput, + DataTuple + ], + "message": str, + }, + total=False +) + + +class MultiPropertiesSchemaDict(schemas.immutabledict[str, typing.Union[ + str, + typing.Tuple[schemas.OUTPUT_BASE_TYPES], + int, +]]): + + __required_keys__: typing.FrozenSet[str] = frozenset({ + "status", + }) + __optional_keys__: typing.FrozenSet[str] = frozenset({ + "data", + "message", + }) + + def __new__( + cls, + *, + status: int, + data: typing.Union[ + DataTupleInput, + DataTuple, + schemas.Unset + ] = schemas.unset, + message: typing.Union[ + str, + schemas.Unset + ] = schemas.unset, + configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, + ): + arg_: typing.Dict[str, typing.Any] = { + "status": status, + } + for key_, val in ( + ("data", data), + ("message", message), + ): + if isinstance(val, schemas.Unset): + continue + arg_[key_] = val + used_arg_ = typing.cast(MultiPropertiesSchemaDictInput, arg_) + return MultiPropertiesSchema.validate(used_arg_, configuration=configuration_) + + @staticmethod + def from_dict_( + arg: typing.Union[ + MultiPropertiesSchemaDictInput, + MultiPropertiesSchemaDict + ], + configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None + ) -> MultiPropertiesSchemaDict: + return MultiPropertiesSchema.validate(arg, configuration=configuration) + + @property + def status(self) -> int: + return typing.cast( + int, + self.__getitem__("status") + ) + + @property + def data(self) -> typing.Union[DataTuple, schemas.Unset]: + val = self.get("data", schemas.unset) + if isinstance(val, schemas.Unset): + return val + return typing.cast( + DataTuple, + val + ) + + @property + def message(self) -> typing.Union[str, schemas.Unset]: + val = self.get("message", schemas.unset) + if isinstance(val, schemas.Unset): + return val + return typing.cast( + str, + val + ) + + +class MultiPropertiesSchemaDictInput(MultiPropertiesSchemaRequiredDictInput, MultiPropertiesSchemaOptionalDictInput): + pass + + +@dataclasses.dataclass(frozen=True) +class MultiPropertiesSchema( + schemas.Schema[MultiPropertiesSchemaDict, tuple] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + types: typing.FrozenSet[typing.Type] = frozenset({schemas.immutabledict}) + required: typing.FrozenSet[str] = frozenset({ + "status", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + type_to_output_cls: typing.Mapping[ + typing.Type, + typing.Type + ] = dataclasses.field( + default_factory=lambda: { + schemas.immutabledict: MultiPropertiesSchemaDict + } + ) + + @classmethod + def validate( + cls, + arg: typing.Union[ + MultiPropertiesSchemaDictInput, + MultiPropertiesSchemaDict, + ], + configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None + ) -> MultiPropertiesSchemaDict: + return super().validate_base( + arg, + configuration=configuration, + ) + diff --git a/samples/client/petstore/python/src/petstore_api/components/schemas/__init__.py b/samples/client/petstore/python/src/petstore_api/components/schemas/__init__.py index 325e3a54b44..bb4af2063cf 100644 --- a/samples/client/petstore/python/src/petstore_api/components/schemas/__init__.py +++ b/samples/client/petstore/python/src/petstore_api/components/schemas/__init__.py @@ -74,6 +74,7 @@ from petstore_api.components.schema.integer_min15 import IntegerMin15 from petstore_api.components.schema.isosceles_triangle import IsoscelesTriangle from petstore_api.components.schema.items import Items +from petstore_api.components.schema.items_schema import ItemsSchema from petstore_api.components.schema.json_patch_request import JSONPatchRequest from petstore_api.components.schema.json_patch_request_add_replace_test import JSONPatchRequestAddReplaceTest from petstore_api.components.schema.json_patch_request_move_copy import JSONPatchRequestMoveCopy @@ -81,6 +82,7 @@ from petstore_api.components.schema.map_test import MapTest from petstore_api.components.schema.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass from petstore_api.components.schema.money import Money +from petstore_api.components.schema.multi_properties_schema import MultiPropertiesSchema from petstore_api.components.schema.my_object_dto import MyObjectDto from petstore_api.components.schema.name import Name from petstore_api.components.schema.no_additional_properties import NoAdditionalProperties diff --git a/samples/client/petstore/python/test/components/schema/test_items_schema.py b/samples/client/petstore/python/test/components/schema/test_items_schema.py new file mode 100644 index 00000000000..a776221914d --- /dev/null +++ b/samples/client/petstore/python/test/components/schema/test_items_schema.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. # noqa: E501 + The version of the OpenAPI document: 1.0.0 + Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator +""" + +import unittest + +import petstore_api +from petstore_api.components.schema.items_schema import ItemsSchema +from petstore_api.configurations import schema_configuration + + +class TestItemsSchema(unittest.TestCase): + """ItemsSchema unit test stubs""" + configuration = schema_configuration.SchemaConfiguration( + disabled_json_schema_keywords={'format'} + ) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/components/schema/test_multi_properties_schema.py b/samples/client/petstore/python/test/components/schema/test_multi_properties_schema.py new file mode 100644 index 00000000000..284be1a6b35 --- /dev/null +++ b/samples/client/petstore/python/test/components/schema/test_multi_properties_schema.py @@ -0,0 +1,25 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. # noqa: E501 + The version of the OpenAPI document: 1.0.0 + Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator +""" + +import unittest + +import petstore_api +from petstore_api.components.schema.multi_properties_schema import MultiPropertiesSchema +from petstore_api.configurations import schema_configuration + + +class TestMultiPropertiesSchema(unittest.TestCase): + """MultiPropertiesSchema unit test stubs""" + configuration = schema_configuration.SchemaConfiguration( + disabled_json_schema_keywords={'format'} + ) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/main/java/org/openapijsonschematools/codegen/generators/DefaultGenerator.java b/src/main/java/org/openapijsonschematools/codegen/generators/DefaultGenerator.java index aa467a0700b..e8ae7a0a972 100644 --- a/src/main/java/org/openapijsonschematools/codegen/generators/DefaultGenerator.java +++ b/src/main/java/org/openapijsonschematools/codegen/generators/DefaultGenerator.java @@ -3708,7 +3708,7 @@ protected LinkedHashMapWithContext getOptionalProperties(LinkedHa continue; } final CodegenSchema prop = entry.getValue(); - if (prop.refInfo != null) { + if (prop.hasAnyRefs()) { allAreInline = false; } optionalProperties.put(key, prop); diff --git a/src/test/resources/3_0/python/petstore_customized.yaml b/src/test/resources/3_0/python/petstore_customized.yaml index c411b7bb937..7bfc41ebead 100644 --- a/src/test/resources/3_0/python/petstore_customized.yaml +++ b/src/test/resources/3_0/python/petstore_customized.yaml @@ -3448,4 +3448,28 @@ components: minimum: 10 exclusiveMinimum: true maximum: 12 - exclusiveMaximum: true \ No newline at end of file + exclusiveMaximum: true + MultiPropertiesSchema: + properties: + status: + type: integer + format: int32 + data: + items: + $ref: '#/components/schemas/ItemsSchema' + type: array + message: + type: string + type: object + required: + - status + additionalProperties: false + ItemsSchema: + type: object + properties: + name: + type: string + additionalProperty: + type: string + secondAdditionalProperty: + type: string \ No newline at end of file From dee64f7d27fde20f94255194ddefb6776818a135 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Mon, 8 Apr 2024 12:27:08 -0700 Subject: [PATCH 2/2] Sample regen, property name adjusted to prevent collision --- .../petstore/java/.openapi-generator/FILES | 2 -- .../docs/components/schemas/ItemsSchema.md | 32 ++++++++--------- .../components/schemas/ItemsSchema.java | 34 +++++++++---------- .../docs/components/schema/items_schema.md | 6 ++-- .../components/schema/items_schema.py | 14 ++++---- .../3_0/python/petstore_customized.yaml | 2 +- 6 files changed, 44 insertions(+), 46 deletions(-) diff --git a/samples/client/petstore/java/.openapi-generator/FILES b/samples/client/petstore/java/.openapi-generator/FILES index ca71993fd68..7631fcda9c8 100644 --- a/samples/client/petstore/java/.openapi-generator/FILES +++ b/samples/client/petstore/java/.openapi-generator/FILES @@ -1699,8 +1699,6 @@ src/main/java/org/openapijsonschematools/client/servers/ServerWithVariables.java src/main/java/org/openapijsonschematools/client/servers/ServerWithoutVariables.java src/main/java/org/openapijsonschematools/client/servers/server0/Variables.java src/main/java/org/openapijsonschematools/client/servers/server1/Variables.java -src/test/java/org/openapijsonschematools/client/components/schemas/ItemsSchemaTest.java -src/test/java/org/openapijsonschematools/client/components/schemas/MultiPropertiesSchemaTest.java src/test/java/org/openapijsonschematools/client/configurations/JsonSchemaKeywordFlagsTest.java src/test/java/org/openapijsonschematools/client/header/ContentHeaderTest.java src/test/java/org/openapijsonschematools/client/header/SchemaHeaderTest.java diff --git a/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md b/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md index 3f4e1664e0a..ce6151620b9 100644 --- a/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md +++ b/samples/client/petstore/java/docs/components/schemas/ItemsSchema.md @@ -20,9 +20,9 @@ A class that contains necessary nested | sealed interface | [ItemsSchema.SecondAdditionalPropertyBoxed](#secondadditionalpropertyboxed)
sealed interface for validated payloads | | record | [ItemsSchema.SecondAdditionalPropertyBoxedString](#secondadditionalpropertyboxedstring)
boxed class to store validated String payloads | | static class | [ItemsSchema.SecondAdditionalProperty](#secondadditionalproperty)
schema class | -| sealed interface | [ItemsSchema.AdditionalPropertyBoxed](#additionalpropertyboxed)
sealed interface for validated payloads | -| record | [ItemsSchema.AdditionalPropertyBoxedString](#additionalpropertyboxedstring)
boxed class to store validated String payloads | -| static class | [ItemsSchema.AdditionalProperty](#additionalproperty)
schema class | +| sealed interface | [ItemsSchema.SomePropertyBoxed](#somepropertyboxed)
sealed interface for validated payloads | +| record | [ItemsSchema.SomePropertyBoxedString](#somepropertyboxedstring)
boxed class to store validated String payloads | +| static class | [ItemsSchema.SomeProperty](#someproperty)
schema class | | sealed interface | [ItemsSchema.NameBoxed](#nameboxed)
sealed interface for validated payloads | | record | [ItemsSchema.NameBoxedString](#nameboxedstring)
boxed class to store validated String payloads | | static class | [ItemsSchema.Name](#name)
schema class | @@ -79,7 +79,7 @@ ItemsSchema.ItemsSchemaMap validatedPayload = new ItemsSchema.ItemsSchemaMapBuilder() .name("a") - .additionalProperty("a") + .someProperty("a") .secondAdditionalProperty("a") @@ -92,7 +92,7 @@ ItemsSchema.ItemsSchemaMap validatedPayload = | Modifier and Type | Field and Description | | ----------------- | ---------------------- | | Set> | type = Set.of(Map.class) | -| Map> | properties = Map.ofEntries(
    new PropertyEntry("name", [Name.class](#name))),
    new PropertyEntry("additionalProperty", [AdditionalProperty.class](#additionalproperty))),
    new PropertyEntry("secondAdditionalProperty", [SecondAdditionalProperty.class](#secondadditionalproperty)))
)
| +| Map> | properties = Map.ofEntries(
    new PropertyEntry("name", [Name.class](#name))),
    new PropertyEntry("someProperty", [SomeProperty.class](#someproperty))),
    new PropertyEntry("secondAdditionalProperty", [SecondAdditionalProperty.class](#secondadditionalproperty)))
)
| ### Method Summary | Modifier and Type | Method and Description | @@ -118,7 +118,7 @@ A class that builds the Map input type | ----------------- | ---------------------- | | Map | build()
Returns map input that should be used with Schema.validate | | [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | name(String value) | -| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String value) | +| [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | someProperty(String value) | | [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | secondAdditionalProperty(String value) | | [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, Void value) | | [ItemsSchemaMapBuilder](#itemsschemamapbuilder) | additionalProperty(String key, boolean value) | @@ -141,7 +141,7 @@ A class to store validated Map payloads | ----------------- | ---------------------- | | static [ItemsSchemaMap](#itemsschemamap) | of([Map](#itemsschemamapbuilder) arg, SchemaConfiguration configuration) | | String | name()
[optional] | -| String | additionalProperty()
[optional] | +| String | someProperty()
[optional] | | String | secondAdditionalProperty()
[optional] | | @Nullable Object | getAdditionalProperty(String name)
provides type safety for additional properties | @@ -180,23 +180,23 @@ A schema class that validates payloads | validate | | validateAndBox | -## AdditionalPropertyBoxed -public sealed interface AdditionalPropertyBoxed
+## SomePropertyBoxed +public sealed interface SomePropertyBoxed
permits
-[AdditionalPropertyBoxedString](#additionalpropertyboxedstring) +[SomePropertyBoxedString](#somepropertyboxedstring) sealed interface that stores validated payloads using boxed classes -## AdditionalPropertyBoxedString -public record AdditionalPropertyBoxedString
-implements [AdditionalPropertyBoxed](#additionalpropertyboxed) +## SomePropertyBoxedString +public record SomePropertyBoxedString
+implements [SomePropertyBoxed](#somepropertyboxed) record that stores validated String payloads, sealed permits implementation ### Constructor Summary | Constructor and Description | | --------------------------- | -| AdditionalPropertyBoxedString(String data)
Creates an instance, private visibility | +| SomePropertyBoxedString(String data)
Creates an instance, private visibility | ### Method Summary | Modifier and Type | Method and Description | @@ -204,8 +204,8 @@ record that stores validated String payloads, sealed permits implementation | String | data()
validated payload | | @Nullable Object | getData()
validated payload | -## AdditionalProperty -public static class AdditionalProperty
+## SomeProperty +public static class SomeProperty
extends StringJsonSchema.StringJsonSchema1 A schema class that validates payloads diff --git a/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java index b59c1d65bc9..4f39912a673 100644 --- a/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java +++ b/samples/client/petstore/java/src/main/java/org/openapijsonschematools/client/components/schemas/ItemsSchema.java @@ -39,11 +39,11 @@ public static Name getInstance() { } - public static class AdditionalProperty extends StringJsonSchema.StringJsonSchema1 { - private static @Nullable AdditionalProperty instance = null; - public static AdditionalProperty getInstance() { + public static class SomeProperty extends StringJsonSchema.StringJsonSchema1 { + private static @Nullable SomeProperty instance = null; + public static SomeProperty getInstance() { if (instance == null) { - instance = new AdditionalProperty(); + instance = new SomeProperty(); } return instance; } @@ -68,7 +68,7 @@ protected ItemsSchemaMap(FrozenMap<@Nullable Object> m) { public static final Set requiredKeys = Set.of(); public static final Set optionalKeys = Set.of( "name", - "additionalProperty", + "someProperty", "secondAdditionalProperty" ); public static ItemsSchemaMap of(Map arg, SchemaConfiguration configuration) throws ValidationException { @@ -85,12 +85,12 @@ public String name() throws UnsetPropertyException { return (String) value; } - public String additionalProperty() throws UnsetPropertyException { - String key = "additionalProperty"; + public String someProperty() throws UnsetPropertyException { + String key = "someProperty"; throwIfKeyNotPresent(key); @Nullable Object value = get(key); if (!(value instanceof String)) { - throw new RuntimeException("Invalid value stored for additionalProperty"); + throw new RuntimeException("Invalid value stored for someProperty"); } return (String) value; } @@ -123,14 +123,14 @@ default T name(String value) { } } - public interface SetterForAdditionalProperty { + public interface SetterForSomeProperty { Map getInstance(); - T getBuilderAfterAdditionalProperty(Map instance); + T getBuilderAfterSomeProperty(Map instance); - default T additionalProperty(String value) { + default T someProperty(String value) { var instance = getInstance(); - instance.put("additionalProperty", value); - return getBuilderAfterAdditionalProperty(instance); + instance.put("someProperty", value); + return getBuilderAfterSomeProperty(instance); } } @@ -145,11 +145,11 @@ default T secondAdditionalProperty(String value) { } } - public static class ItemsSchemaMapBuilder extends UnsetAddPropsSetter implements GenericBuilder>, SetterForName, SetterForAdditionalProperty, SetterForSecondAdditionalProperty { + public static class ItemsSchemaMapBuilder extends UnsetAddPropsSetter implements GenericBuilder>, SetterForName, SetterForSomeProperty, SetterForSecondAdditionalProperty { private final Map instance; private static final Set knownKeys = Set.of( "name", - "additionalProperty", + "someProperty", "secondAdditionalProperty" ); public Set getKnownKeys() { @@ -167,7 +167,7 @@ public ItemsSchemaMapBuilder() { public ItemsSchemaMapBuilder getBuilderAfterName(Map instance) { return this; } - public ItemsSchemaMapBuilder getBuilderAfterAdditionalProperty(Map instance) { + public ItemsSchemaMapBuilder getBuilderAfterSomeProperty(Map instance) { return this; } public ItemsSchemaMapBuilder getBuilderAfterSecondAdditionalProperty(Map instance) { @@ -205,7 +205,7 @@ protected ItemsSchema1() { .type(Set.of(Map.class)) .properties(Map.ofEntries( new PropertyEntry("name", Name.class), - new PropertyEntry("additionalProperty", AdditionalProperty.class), + new PropertyEntry("someProperty", SomeProperty.class), new PropertyEntry("secondAdditionalProperty", SecondAdditionalProperty.class) )) ); diff --git a/samples/client/petstore/python/docs/components/schema/items_schema.md b/samples/client/petstore/python/docs/components/schema/items_schema.md index 3337064f785..5bac34fbb5b 100644 --- a/samples/client/petstore/python/docs/components/schema/items_schema.md +++ b/samples/client/petstore/python/docs/components/schema/items_schema.md @@ -16,7 +16,7 @@ type: typing.Mapping[str, schemas.INPUT_TYPES_ALL] Key | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | str | | [optional] -**additionalProperty** | str | | [optional] +**someProperty** | str | | [optional] **secondAdditionalProperty** | str | | [optional] **any_string_name** | dict, schemas.immutabledict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] @@ -29,7 +29,7 @@ base class: schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES] Keyword Argument | Type | Description | Notes ---------------- | ---- | ----------- | ----- **name** | str, schemas.Unset | | [optional] -**additionalProperty** | str, schemas.Unset | | [optional] +**someProperty** | str, schemas.Unset | | [optional] **secondAdditionalProperty** | str, schemas.Unset | | [optional] **kwargs** | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] typed value is accessed with the get_additional_property_ method @@ -37,7 +37,7 @@ Keyword Argument | Type | Description | Notes Property | Type | Description | Notes -------- | ---- | ----------- | ----- **name** | str, schemas.Unset | | [optional] -**additionalProperty** | str, schemas.Unset | | [optional] +**someProperty** | str, schemas.Unset | | [optional] **secondAdditionalProperty** | str, schemas.Unset | | [optional] ### methods diff --git a/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py b/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py index dd1fbbb4dfc..08e440d5983 100644 --- a/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py +++ b/samples/client/petstore/python/src/petstore_api/components/schema/items_schema.py @@ -11,13 +11,13 @@ from petstore_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary] Name: typing_extensions.TypeAlias = schemas.StrSchema -AdditionalProperty: typing_extensions.TypeAlias = schemas.StrSchema +SomeProperty: typing_extensions.TypeAlias = schemas.StrSchema SecondAdditionalProperty: typing_extensions.TypeAlias = schemas.StrSchema Properties = typing.TypedDict( 'Properties', { "name": typing.Type[Name], - "additionalProperty": typing.Type[AdditionalProperty], + "someProperty": typing.Type[SomeProperty], "secondAdditionalProperty": typing.Type[SecondAdditionalProperty], } ) @@ -29,7 +29,7 @@ class ItemsSchemaDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]): }) __optional_keys__: typing.FrozenSet[str] = frozenset({ "name", - "additionalProperty", + "someProperty", "secondAdditionalProperty", }) @@ -40,7 +40,7 @@ def __new__( str, schemas.Unset ] = schemas.unset, - additionalProperty: typing.Union[ + someProperty: typing.Union[ str, schemas.Unset ] = schemas.unset, @@ -54,7 +54,7 @@ def __new__( arg_: typing.Dict[str, typing.Any] = {} for key_, val in ( ("name", name), - ("additionalProperty", additionalProperty), + ("someProperty", someProperty), ("secondAdditionalProperty", secondAdditionalProperty), ): if isinstance(val, schemas.Unset): @@ -85,8 +85,8 @@ def name(self) -> typing.Union[str, schemas.Unset]: ) @property - def additionalProperty(self) -> typing.Union[str, schemas.Unset]: - val = self.get("additionalProperty", schemas.unset) + def someProperty(self) -> typing.Union[str, schemas.Unset]: + val = self.get("someProperty", schemas.unset) if isinstance(val, schemas.Unset): return val return typing.cast( diff --git a/src/test/resources/3_0/python/petstore_customized.yaml b/src/test/resources/3_0/python/petstore_customized.yaml index 7bfc41ebead..9a7aec687da 100644 --- a/src/test/resources/3_0/python/petstore_customized.yaml +++ b/src/test/resources/3_0/python/petstore_customized.yaml @@ -3469,7 +3469,7 @@ components: properties: name: type: string - additionalProperty: + someProperty: type: string secondAdditionalProperty: type: string \ No newline at end of file