Skip to content

Commit

Permalink
fix(generator): OpenAPI generator issues discovered while testing aga…
Browse files Browse the repository at this point in the history
…inst petstore example (#1679)
  • Loading branch information
chillleader authored Jan 16, 2024
1 parent 69b3634 commit c98bd48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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

0 comments on commit c98bd48

Please sign in to comment.