Support openapi http proxy using openapi.yaml#778
Support openapi http proxy using openapi.yaml#778jfallows merged 105 commits intoaklivity:developfrom akrambek:story/740
Conversation
…artial data frame while computing crc32c value
| "dependencies": | ||
| [ | ||
| "io.aklivity.zilla:binding-amqp", | ||
| "io.aklivity.zilla:binding-openapi", |
There was a problem hiding this comment.
These are in alphabetical order, please move to sorted position.
| */ | ||
| package io.aklivity.zilla.specs.binding.openapi; | ||
|
|
||
| public class OpenapiSpecs |
There was a problem hiding this comment.
This should probably be final with a private constructor.
| @Specification({ | ||
| "${http}/reject.incorrect.origin/client", | ||
| "${http}/reject.incorrect.origin/server" | ||
| }) | ||
| public void shouldRejectIncorrectOrigin() throws Exception |
There was a problem hiding this comment.
Recommend we rename this scenario to shouldRejectNonCompositeOrigin and scripts to reject.non.composite.origin.
incubator/binding-openapi/pom.xml
Outdated
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>binding-http</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>binding-tcp</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>binding-tls</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>catalog-inline</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>model-core</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.aklivity.zilla</groupId> | ||
| <artifactId>model-json</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> |
There was a problem hiding this comment.
Please move all these default scope dependencies after provided scope and before test scope.
| private static final String TLS_NAME = "tls"; | ||
| private static final String HTTP_NAME = "http"; | ||
| private static final String SPECS_NAME = "specs"; | ||
| private OptionsConfigAdapter optionsAdapter; |
There was a problem hiding this comment.
| private OptionsConfigAdapter optionsAdapter; | |
| private OptionsConfigAdapter tlsOptions; | |
| private OptionsConfigAdapter httpOptions; |
and a constructor
public OpenapiOptionsConfigAdapter()
{
tlsOptions.adaptType("tls");
httpOptions.adaptType("http");
}
There was a problem hiding this comment.
I guess you mean in public void adaptContext since there you have access to context
| private SchemaView resolveSchemaForJsonContentType( | ||
| Map<String, MediaType> content, | ||
| OpenApi openApi) | ||
| { | ||
| MediaType mediaType = null; | ||
| if (content != null) | ||
| { | ||
| for (String contentType : content.keySet()) | ||
| { | ||
| if (jsonContentType.reset(contentType).matches()) | ||
| { | ||
| mediaType = content.get(contentType); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return mediaType == null ? null : SchemaView.of(openApi.components.schemas, mediaType.schema); | ||
| } |
There was a problem hiding this comment.
This helper method should go after all the injectXxx methods for improved readability.
| @Specification({ | ||
| "${http}/reject.incorrect.origin/client" | ||
| }) | ||
| public void shouldRejectIncorrectOrigin() throws Exception |
There was a problem hiding this comment.
shouldRejectNonCompositeOrigin()
| OpenApi openApi = null; | ||
| try (Jsonb jsonb = JsonbBuilder.create()) | ||
| { | ||
| openApi = jsonb.fromJson(openapiText, OpenApi.class); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| rethrowUnchecked(ex); | ||
| } |
There was a problem hiding this comment.
Let's make sure we are using a validating schema to parse OpenAPI spec so we can communicate errors meaningfully.
Also, support OpenAPI spec 3.0, 3,1, perhaps also 2.0 since OpenAPI has been around for a long time?
jfallows
left a comment
There was a problem hiding this comment.
Looks good, just the OpenAPI schema parsing left.
Recommend we store the openapi.3.0.schema.json in binding-openapi.spec so it can easily be reused from both binding-openapi and binding-openapi-asyncpi implementations.
incubator/binding-openapi/pom.xml
Outdated
| </artifactItem> | ||
| </artifactItems> | ||
| <includes>io/aklivity/zilla/specs/binding/openapi/schema/openapi.schema.patch.json</includes> | ||
| <includes>io/aklivity/zilla/specs/binding/openapi/schema/*.json</includes> |
There was a problem hiding this comment.
Let's make this explicit, as we might decide to move the supporting openapi version-specific schemas to a different directory.
| <includes>io/aklivity/zilla/specs/binding/openapi/schema/*.json</includes> | |
| <includes>io/aklivity/zilla/specs/binding/openapi/schema/openapi.schema.patch.json</includes> | |
| <includes>io/aklivity/zilla/specs/binding/openapi/schema/openapi.*.schema.json</includes> |
| if (validateOpenapiSchema(openapiText)) | ||
| { | ||
| openApi = jsonb.fromJson(openapiText, OpenApi.class); | ||
| try (Jsonb jsonb = JsonbBuilder.create()) | ||
| { | ||
| openApi = jsonb.fromJson(openapiText, OpenApi.class); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| rethrowUnchecked(ex); | ||
| } | ||
| } | ||
| return openApi; | ||
| } | ||
|
|
||
| private boolean validateOpenapiSchema( | ||
| String openapiText) | ||
| { | ||
| List<Exception> errors = new LinkedList<>(); | ||
|
|
||
| boolean valid = false; | ||
|
|
||
| try | ||
| { | ||
| JsonValidationService service = JsonValidationService.newInstance(); | ||
|
|
||
| String openApiVersion = detectOpenApiVersion(openapiText); | ||
| InputStream schemaInput = selectSchemaPathForVersion(openApiVersion); | ||
|
|
||
| JsonSchema schema = service.readSchema(schemaInput); | ||
| ProblemHandler handler = service.createProblemPrinter(msg -> errors.add(new ConfigException(msg))); | ||
|
|
||
| String readable = openapiText.stripTrailing(); | ||
| Reader openapiReader = new StringReader(readable); | ||
|
|
||
| JsonReader reader = service.createReader(openapiReader, schema, handler); | ||
|
|
||
| JsonStructure json = reader.read(); | ||
| valid = json != null; |
There was a problem hiding this comment.
Please use JsonProvider provider = service.createJsonProvider(schema, problemHandler) to create a validating JsonProvider.
Then use JsonbBuilder.newBuilder().withProvider(provider).build() instead of Jsonb.create().
This will let you combine both methods into one and do a single pass of the the openapi document during (validating) parse / build.
| */ | ||
| package io.aklivity.zilla.runtime.binding.openapi.internal.model; | ||
|
|
||
| public class BearerAuth |
There was a problem hiding this comment.
| public class BearerAuth | |
| public class OpenApiBearerAuth |
Please include OpenApi prefix on all model class names.
| import io.aklivity.zilla.runtime.binding.openapi.internal.model.Operation; | ||
| import io.aklivity.zilla.runtime.binding.openapi.internal.model.ResponseByContentType; | ||
|
|
||
| public final class OperationView |
There was a problem hiding this comment.
| public final class OperationView | |
| public final class OpenApiOperationView |
Please include OpenApi prefix on all view class names.
Description
Support openapi http proxy using openapi.yaml .
Fixes #740