Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
*/
// CHECKSTYLE:OFF
public class Order
// CHECKSTYLE:ON
{
// CHECKSTYLE:ON
@JsonProperty( "productId" )
private Long productId;

Expand Down Expand Up @@ -154,7 +154,7 @@ public Order totalPrice( @Nullable final Float totalPrice )
*
* @return totalPrice The totalPrice of this {@link Order} instance.
*/
@Nullable
@Nonnull
public Float getTotalPrice()
{
return totalPrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
*/
// CHECKSTYLE:OFF
public class OrderWithTimestamp
// CHECKSTYLE:ON
{
// CHECKSTYLE:ON
@JsonProperty( "productId" )
private Long productId;

Expand Down Expand Up @@ -158,7 +158,7 @@ public OrderWithTimestamp totalPrice( @Nullable final Float totalPrice )
*
* @return totalPrice The totalPrice of this {@link OrderWithTimestamp} instance.
*/
@Nullable
@Nonnull
public Float getTotalPrice()
{
return totalPrice;
Expand Down Expand Up @@ -266,7 +266,7 @@ public OrderWithTimestamp timestamp( @Nullable final OffsetDateTime timestamp )
*
* @return timestamp The timestamp of this {@link OrderWithTimestamp} instance.
*/
@Nullable
@Nonnull
public OffsetDateTime getTimestamp()
{
return timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
*/
// CHECKSTYLE:OFF
public class Soda
// CHECKSTYLE:ON
{
// CHECKSTYLE:ON
@JsonProperty( "name" )
private String name;

Expand Down Expand Up @@ -268,7 +268,7 @@ public Soda packaging( @Nullable final PackagingEnum packaging )
*
* @return packaging The packaging of this {@link Soda} instance.
*/
@Nullable
@Nonnull
public PackagingEnum getPackaging()
{
return packaging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
*/
// CHECKSTYLE:OFF
public class SodaWithId
// CHECKSTYLE:ON
{
// CHECKSTYLE:ON
@JsonProperty( "name" )
private String name;

Expand Down Expand Up @@ -271,7 +271,7 @@ public SodaWithId packaging( @Nullable final PackagingEnum packaging )
*
* @return packaging The packaging of this {@link SodaWithId} instance.
*/
@Nullable
@Nonnull
public PackagingEnum getPackaging()
{
return packaging;
Expand Down Expand Up @@ -343,7 +343,7 @@ public SodaWithId id( @Nullable final Long id )
*
* @return id The id of this {@link SodaWithId} instance.
*/
@Nullable
@Nonnull
public Long getId()
{
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public class DataModelGeneratorMojo extends AbstractMojo
@Parameter( property = "openapi.generate.enableOneOfAnyOfGeneration", defaultValue = "false" )
private boolean enableOneOfAnyOfGeneration;

/**
* Generate model classes. Default is true.
*/
@Parameter( property = "openapi.generate.generateModels", defaultValue = "true" )
private boolean generateModels;

/**
* Generate API classes (client classes). Default is true.
*/
@Parameter( property = "openapi.generate.generateApis", defaultValue = "true" )
private boolean generateApis;

Comment on lines +121 to +132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Question)

Why not have this as separate PR? It's unrelated to oneof / anyof.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to save time

/**
* Defines a list of additional properties that will be passed to the Java generator.
*/
Expand Down Expand Up @@ -179,6 +191,8 @@ Try<GenerationConfiguration> retrieveGenerationConfiguration()
.deleteOutputDirectory(deleteOutputDirectory)
.additionalProperties(additionalProperties)
.oneOfAnyOfGenerationEnabled(enableOneOfAnyOfGeneration)
.generateModels(generateModels)
.generateApis(generateApis)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -40,8 +39,9 @@
* NewSoda
*/
// CHECKSTYLE:OFF
public class NewSoda {
public class NewSoda
// CHECKSTYLE:ON
{
@JsonProperty("name")
private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -40,8 +39,9 @@
* Soda
*/
// CHECKSTYLE:OFF
public class Soda {
public class Soda
// CHECKSTYLE:ON
{
@JsonProperty("id")
private Long id;

Expand Down Expand Up @@ -76,7 +76,7 @@ public class Soda {
* Get id
* @return id The id of this {@link Soda} instance.
*/
@Nullable
@Nonnull
public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -40,8 +39,9 @@
* UpdateSoda
*/
// CHECKSTYLE:OFF
public class UpdateSoda {
public class UpdateSoda
// CHECKSTYLE:ON
{
@JsonProperty("name")
private String name;

Expand Down Expand Up @@ -73,7 +73,7 @@ public class UpdateSoda {
* Get name
* @return name The name of this {@link UpdateSoda} instance.
*/
@Nullable
@Nonnull
public String getName() {
return name;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void setName( @Nullable final String name) {
* Get brand
* @return brand The brand of this {@link UpdateSoda} instance.
*/
@Nullable
@Nonnull
public String getBrand() {
return brand;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public void setBrand( @Nullable final String brand) {
* Get flavor
* @return flavor The flavor of this {@link UpdateSoda} instance.
*/
@Nullable
@Nonnull
public String getFlavor() {
return flavor;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public void setFlavor( @Nullable final String flavor) {
* Get price
* @return price The price of this {@link UpdateSoda} instance.
*/
@Nullable
@Nonnull
public Float getPrice() {
return price;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static ClientOptInput convertGenerationConfiguration(
@Nonnull final GenerationConfiguration generationConfiguration,
@Nonnull final Path inputSpec )
{
setGlobalSettings();
setGlobalSettings(generationConfiguration);
final var inputSpecFile = inputSpec.toString();

final var config = createCodegenConfig();
Expand Down Expand Up @@ -96,10 +96,14 @@ public OperationsMap postProcessOperationsWithModels(
};
}

private static void setGlobalSettings()
private static void setGlobalSettings( @Nonnull final GenerationConfiguration configuration )
{
GlobalSettings.setProperty(CodegenConstants.APIS, "");
GlobalSettings.setProperty(CodegenConstants.MODELS, "");
if( configuration.isGenerateApis() ) {
GlobalSettings.setProperty(CodegenConstants.APIS, "");
}
if( configuration.isGenerateModels() ) {
GlobalSettings.setProperty(CodegenConstants.MODELS, "");
}
GlobalSettings.setProperty(CodegenConstants.MODEL_TESTS, Boolean.FALSE.toString());
GlobalSettings.setProperty(CodegenConstants.MODEL_DOCS, Boolean.FALSE.toString());
GlobalSettings.setProperty(CodegenConstants.API_TESTS, Boolean.FALSE.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.sap.cloud.sdk.datamodel.openapi.generator;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -51,17 +50,14 @@ class PreprocessingStepOrchestrator
* {@code anyOfOneOfGenerationEnabled}
*
* @param anyOfOneOfGenerationEnabled
* true if clients should be generated for input specification with oneOf, anyOf
*
* @return this
*/
PreprocessingStepOrchestrator enableAnyOfOneOfGeneration( @Nonnull final boolean anyOfOneOfGenerationEnabled )
PreprocessingStepOrchestrator enableAnyOfOneOfGeneration( final boolean anyOfOneOfGenerationEnabled )
{
if( !anyOfOneOfGenerationEnabled ) {
steps.add(ValidationKeywordsPreprocessor::new);
} else {
log
.warn(
"oneOf/anyOf keywords processing is turned on, the generated client may not be feature complete and work as expected for all cases involving anyOf/oneOf");
}
return this;
}
Expand Down Expand Up @@ -115,7 +111,7 @@ private Path writeProcessedSpecToTempFile( @Nonnull final JsonNode rootNode, @No
"." + fileFormat.getFileExtensions().get(0));

final String content = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode);
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
Files.writeString(path, content);

return path.normalize().toAbsolutePath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class GenerationConfiguration
@Builder.Default
boolean oneOfAnyOfGenerationEnabled = false;

@Builder.Default
boolean generateModels = true;

@Builder.Default
boolean generateApis = true;

/**
* Indicates whether to use the default SAP copyright header for generated files.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
{{#withXml}}
import com.fasterxml.jackson.dataformat.xml.annotation.*;
{{/withXml}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
{{/swagger2AnnotationLibrary}}
{{#jackson}}
{{#isClassnameSanitized}}
{{^hasDiscriminatorWithNonEmptyMapping}}
@JsonTypeName("{{name}}")
{{/hasDiscriminatorWithNonEmptyMapping}}
{{/isClassnameSanitized}}
{{/jackson}}
{{>additionalModelTypeAnnotations}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}{{^isReleased}}
@Beta{{/isReleased}}// CHECKSTYLE:OFF
public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}{
public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}}
// CHECKSTYLE:ON
{
{{#serializableModel}}
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -203,17 +201,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#deprecated}}
@Deprecated
{{/deprecated}}
{{#required}}
{{#isNullable}}
@Nullable
{{/isNullable}}
{{^isNullable}}
@Nonnull
{{/isNullable}}
{{/required}}
{{^required}}
@Nullable
{{/required}}
{{#jsonb}}
@JsonbProperty("{{baseName}}")
{{/jsonb}}
Expand Down
Loading
Loading