Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(generator): OpenAPI generator issues with Petstore example #1679

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions element-template-generator/congen-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ Note that `congen` will pass all parameters specified after the command name to
For example, the OpenAPI generator accepts the path or URL of the OpenAPI specification as the first parameter,
followed by an optional list of operation IDs to include in the generated template.

The following command will ask the generator to include only the `findPetsById` and `addPet` operations.
The following command will ask the generator to include only the `placeOrder` operation.

```shell
congen generate openapi-outbound https://petstore3.swagger.io/api/v3/openapi.json findPetsById addPet
congen generate openapi-outbound https://petstore3.swagger.io/api/v3/openapi.json placeOrder
```

Note that not all operations in the OpenAPI specification can be converted to a template. The generator will
ignore operations that cannot be converted. To see the list of operations that can be converted, use the `scan` command.

```shell
congen scan openapi-outbound https://petstore3.swagger.io/api/v3/openapi.json
```

```shell

The command below will generate the template with the custom element template ID.

```shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public Integer call() {
return GENERATION_FAILED.getCode();
}
try {
var resultString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(templates);
String resultString;
if (templates.size() == 1) {
resultString = mapper.writeValueAsString(templates.getFirst());
} else {
resultString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(templates);
}
System.out.println(resultString);
return SUCCESS.getCode();
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static PropertyBuilder authDiscriminatorPropertyPrefab(
.label("Authentication")
.optional(false)
.binding(new ZeebeInput("authentication.type"))
.value(choices.get(0).value());
.value(choices.getFirst().value());
}

static PropertyGroup operationDiscriminatorPropertyGroup(Collection<HttpOperation> operations) {
Expand Down Expand Up @@ -327,7 +327,7 @@ private static Property transformProperty(

// shade property id with operation id as there may be duplicates in different operations
builder
.id(operationId + "_" + property.id())
.id(operationId + "_" + property.target().name().toLowerCase() + "_" + property.id())
.label(TemplatePropertiesUtil.transformIdIntoLabel(property.id()))
.description(property.description())
.optional(!property.required())
Expand Down Expand Up @@ -356,7 +356,7 @@ static PropertyGroup requestBodyPropertyGroup(Collection<HttpOperation> operatio
.map(p -> transformProperty(operation.id(), p, "requestBody"))
.toList();

Property bodyAggregationProperty = null;
Property bodyAggregationProperty;
if (bodyProperties.isEmpty()) {
bodyAggregationProperty =
StringProperty.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public static List<OperationParseResult> extractOperations(
});
return operations.stream();
})
.filter(OperationParseResult::supported)
.filter(
operation ->
includeOperations == null
Expand All @@ -138,7 +137,7 @@ private static OperationParseResult extractOperation(
var authenticationOverride = parseAuthentication(operation.getSecurity(), components);

var body = BodyUtil.parseBody(operation.getRequestBody(), components, options);
HttpFeelBuilder bodyFeelExpression = null;
HttpFeelBuilder bodyFeelExpression;

if (body instanceof BodyParseResult.Raw raw) {
bodyFeelExpression = HttpFeelBuilder.preFormatted("=" + raw.rawBody());
Expand Down