-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java client, adds parameter classes (#398)
* Adds parameter base classes * Generates parameter classes * Fixes java parameter filenames, fixes java errors * Fixes in + style value for parameters * Adds 4 separate base classes for parameters * Fixes mvn test run * Fixes build and test errors * Adds parameter tests * Adds parameter docs * Fixes readme links to parameter docs * Docs regen * Samples regen
- Loading branch information
Showing
151 changed files
with
5,951 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...nit_test/java/src/main/java/org/openapijsonschematools/client/header/StyleSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.openapijsonschematools.client.header; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class StyleSerializer extends Rfc6570Serializer { | ||
public static String serializeSimple( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode, | ||
boolean percentEncode | ||
) { | ||
var prefixSeparatorIterator = new PrefixSeparatorIterator("", ","); | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
percentEncode, | ||
prefixSeparatorIterator | ||
); | ||
} | ||
|
||
public static String serializeForm( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode, | ||
boolean percentEncode, | ||
@Nullable PrefixSeparatorIterator iterator, | ||
boolean isCookie | ||
) { | ||
// todo check that the prefix and suffix matches this one | ||
String prefix = isCookie ? "" : "?"; | ||
PrefixSeparatorIterator usedIterator = iterator == null ? new PrefixSeparatorIterator(prefix, "&") : iterator; | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
percentEncode, | ||
usedIterator | ||
); | ||
} | ||
|
||
public static String serializeMatrix( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode | ||
) { | ||
PrefixSeparatorIterator usedIterator = new PrefixSeparatorIterator(";", ";"); | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
true, | ||
usedIterator | ||
); | ||
} | ||
|
||
public static String serializeLabel( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode | ||
) { | ||
PrefixSeparatorIterator usedIterator = new PrefixSeparatorIterator(".", "."); | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
true, | ||
usedIterator | ||
); | ||
} | ||
|
||
public static String serializeSpaceDelimited( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode, | ||
@Nullable PrefixSeparatorIterator iterator | ||
) { | ||
PrefixSeparatorIterator usedIterator = iterator == null ? new PrefixSeparatorIterator("", "%20") : iterator; | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
true, | ||
usedIterator | ||
); | ||
} | ||
|
||
public static String serializePipeDelimited( | ||
@Nullable Object inData, | ||
String name, | ||
boolean explode, | ||
@Nullable PrefixSeparatorIterator iterator | ||
) { | ||
PrefixSeparatorIterator usedIterator = iterator == null ? new PrefixSeparatorIterator("", "|") : iterator; | ||
return rfc6570Expansion( | ||
name, | ||
inData, | ||
explode, | ||
true, | ||
usedIterator | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...a/src/main/java/org/openapijsonschematools/client/parameter/ContentNonQueryParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.mediatype.MediaType; | ||
|
||
import java.util.Map; | ||
|
||
public class ContentNonQueryParameter extends ContentParameter implements NonQueryParameter { | ||
|
||
public ContentNonQueryParameter(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved, Map<String, MediaType<?, ?>> content) { | ||
super(name, inType, required, style, explode, allowReserved, content); | ||
} | ||
|
||
@Override | ||
public Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration) { | ||
return super.serialize(inData, validate, configuration); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...test/java/src/main/java/org/openapijsonschematools/client/parameter/ContentParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.contenttype.ContentTypeDetector; | ||
import org.openapijsonschematools.client.contenttype.ContentTypeSerializer; | ||
import org.openapijsonschematools.client.mediatype.MediaType; | ||
|
||
import java.util.Map; | ||
|
||
public class ContentParameter extends ParameterBase { | ||
public final Map<String, MediaType<?, ?>> content; | ||
|
||
public ContentParameter(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved, Map<String, MediaType<?, ?>> content) { | ||
super(name, inType, required, style, explode, allowReserved); | ||
this.content = content; | ||
} | ||
|
||
protected Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration) { | ||
for (Map.Entry<String, MediaType<?, ?>> entry: content.entrySet()) { | ||
var castInData = validate ? entry.getValue().schema().validate(inData, configuration) : inData ; | ||
String contentType = entry.getKey(); | ||
if (ContentTypeDetector.contentTypeIsJson(contentType)) { | ||
var value = ContentTypeSerializer.toJson(castInData); | ||
return Map.of(name, value); | ||
} else { | ||
throw new RuntimeException("Serialization of "+contentType+" has not yet been implemented"); | ||
} | ||
} | ||
throw new RuntimeException("Invalid value for content, it was empty and must have 1 key value pair"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...java/src/main/java/org/openapijsonschematools/client/parameter/ContentQueryParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
import org.openapijsonschematools.client.mediatype.MediaType; | ||
|
||
import java.util.Map; | ||
|
||
public class ContentQueryParameter extends ContentParameter implements QueryParameter { | ||
|
||
public ContentQueryParameter(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved, Map<String, MediaType<?, ?>> content) { | ||
super(name, inType, required, style, explode, allowReserved, content); | ||
} | ||
|
||
@Override | ||
public Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration, PrefixSeparatorIterator iterator) { | ||
return super.serialize(inData, validate, configuration); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...est/java/src/main/java/org/openapijsonschematools/client/parameter/NonQueryParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
|
||
import java.util.Map; | ||
|
||
public interface NonQueryParameter { | ||
Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration); | ||
} |
39 changes: 39 additions & 0 deletions
39
...it_test/java/src/main/java/org/openapijsonschematools/client/parameter/ParameterBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.header.HeaderBase; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
|
||
public class ParameterBase extends HeaderBase { | ||
public final String name; | ||
public final ParameterInType inType; | ||
|
||
public ParameterBase(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved) { | ||
super(required, style, explode, allowReserved); | ||
this.name = name; | ||
this.inType = inType; | ||
} | ||
|
||
protected ParameterStyle getStyle() { | ||
if (style != null) { | ||
return style; | ||
} | ||
if (inType == ParameterInType.QUERY || inType == ParameterInType.COOKIE) { | ||
return ParameterStyle.FORM; | ||
} | ||
// ParameterInType.HEADER || ParameterInType.PATH | ||
return ParameterStyle.SIMPLE; | ||
} | ||
|
||
public PrefixSeparatorIterator getPrefixSeparatorIterator() { | ||
ParameterStyle usedStyle = getStyle(); | ||
if (usedStyle == ParameterStyle.FORM) { | ||
return new PrefixSeparatorIterator("?", "&"); | ||
} else if (usedStyle == ParameterStyle.SPACE_DELIMITED) { | ||
return new PrefixSeparatorIterator("", "%20"); | ||
} else if (usedStyle == ParameterStyle.PIPE_DELIMITED) { | ||
return new PrefixSeparatorIterator("", "|"); | ||
} | ||
throw new RuntimeException("No iterator possible for style="+usedStyle); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...t_test/java/src/main/java/org/openapijsonschematools/client/parameter/QueryParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
|
||
import java.util.Map; | ||
|
||
public interface QueryParameter { | ||
Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration, PrefixSeparatorIterator iterator); | ||
PrefixSeparatorIterator getPrefixSeparatorIterator(); | ||
} |
20 changes: 20 additions & 0 deletions
20
...va/src/main/java/org/openapijsonschematools/client/parameter/SchemaNonQueryParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
import org.openapijsonschematools.client.schemas.validation.JsonSchema; | ||
|
||
import java.util.Map; | ||
|
||
public class SchemaNonQueryParameter extends SchemaParameter implements NonQueryParameter { | ||
|
||
public SchemaNonQueryParameter(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved, JsonSchema<?> schema) { | ||
super(name, inType, required, style, explode, allowReserved, schema); | ||
} | ||
|
||
@Override | ||
public Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration) { | ||
return super.serialize(inData, validate, configuration, null); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
..._test/java/src/main/java/org/openapijsonschematools/client/parameter/SchemaParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.openapijsonschematools.client.parameter; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.openapijsonschematools.client.configurations.SchemaConfiguration; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
import org.openapijsonschematools.client.header.StyleSerializer; | ||
import org.openapijsonschematools.client.schemas.validation.JsonSchema; | ||
import org.openapijsonschematools.client.header.HeaderBase; | ||
import org.openapijsonschematools.client.header.PrefixSeparatorIterator; | ||
import org.openapijsonschematools.client.header.StyleSerializer; | ||
import org.openapijsonschematools.client.schemas.validation.JsonSchema; | ||
import java.util.Map; | ||
|
||
public class SchemaParameter extends ParameterBase { | ||
public final JsonSchema<?> schema; | ||
|
||
public SchemaParameter(String name, ParameterInType inType, boolean required, @Nullable ParameterStyle style, @Nullable Boolean explode, @Nullable Boolean allowReserved, JsonSchema<?> schema) { | ||
super(name, inType, required, style, explode, allowReserved); | ||
this.schema = schema; | ||
} | ||
|
||
protected Map<String, String> serialize(@Nullable Object inData, boolean validate, SchemaConfiguration configuration, @Nullable PrefixSeparatorIterator iterator) { | ||
var castInData = validate ? schema.validate(inData, configuration) : inData; | ||
ParameterStyle usedStyle = getStyle(); | ||
boolean percentEncode = inType == ParameterInType.QUERY || inType == ParameterInType.PATH; | ||
String value; | ||
boolean usedExplode = explode == null ? usedStyle == ParameterStyle.FORM : explode; | ||
if (usedStyle == ParameterStyle.SIMPLE) { | ||
// header OR path | ||
value = StyleSerializer.serializeSimple(castInData, name, usedExplode, percentEncode); | ||
} else if (usedStyle == ParameterStyle.FORM) { | ||
// query OR cookie | ||
boolean isCookie = inType == ParameterInType.COOKIE; | ||
value = StyleSerializer.serializeForm(castInData, name, usedExplode, percentEncode, iterator, isCookie); | ||
} else if (usedStyle == ParameterStyle.LABEL) { | ||
// path | ||
value = StyleSerializer.serializeLabel(castInData, name, usedExplode); | ||
} else if (usedStyle == ParameterStyle.MATRIX) { | ||
// path | ||
value = StyleSerializer.serializeMatrix(castInData, name, usedExplode); | ||
} else if (usedStyle == ParameterStyle.SPACE_DELIMITED) { | ||
// query | ||
value = StyleSerializer.serializeSpaceDelimited(castInData, name, usedExplode, iterator); | ||
} else if (usedStyle == ParameterStyle.PIPE_DELIMITED) { | ||
// query | ||
value = StyleSerializer.serializePipeDelimited(castInData, name, usedExplode, iterator); | ||
} else { | ||
// usedStyle == ParameterStyle.DEEP_OBJECT | ||
// query | ||
throw new RuntimeException("Style deep object serialization has not yet been implemented."); | ||
} | ||
return Map.of(name, value); | ||
} | ||
} |
Oops, something went wrong.