Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !1202

Add support for using Spring HATEOAS to add links in the spring gener…

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/mwoodland/master into master 6 years ago
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 5

Created by: mwoodland

…ator.

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

Compare
  • master (base)

and
  • latest version
    e569f0e6
    1 commit, 2 years ago

5 files
+ 27
- 1

    Preferences

    File browser
    Compare changes
docs/ge‎nerators‎
spri‎ng.md‎ +3 -0
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
SpringCod‎egen.java‎ +11 -0
resources/‎JavaSpring‎
libraries/‎spring-boot‎
pom.mu‎stache‎ +7 -0
model.m‎ustache‎ +5 -0
pojo.m‎ustache‎ +1 -1
docs/generators/spring.md
+ 3
- 0
  • View file @ e569f0e6


@@ -155,6 +155,9 @@ CONFIG OPTIONS for spring
useOptional
Use Optional container for optional parameters (Default: false)
hateoas
Use Spring HATEOAS library to allow adding HATEOAS links (Default: false)
library
library template (sub-template) to use (Default: spring-boot)
spring-boot - Spring-boot Server application using the SpringFox integration.
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
+ 11
- 0
  • View file @ e569f0e6


@@ -74,6 +74,7 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String IMPLICIT_HEADERS = "implicitHeaders";
public static final String OPENAPI_DOCKET_CONFIG = "swaggerDocketConfig";
public static final String API_FIRST = "apiFirst";
public static final String HATEOAS = "hateoas";
protected String title = "OpenAPI Spring";
protected String configPackage = "org.openapitools.configuration";
@@ -93,6 +94,7 @@ public class SpringCodegen extends AbstractJavaCodegen
protected boolean apiFirst = false;
protected boolean useOptional = false;
protected boolean virtualService = false;
protected boolean hateoas = false;
public SpringCodegen() {
super();
@@ -124,6 +126,7 @@ public class SpringCodegen extends AbstractJavaCodegen
cliOptions.add(CliOption.newBoolean(OPENAPI_DOCKET_CONFIG, "Generate Spring OpenAPI Docket configuration class.", openapiDocketConfig));
cliOptions.add(CliOption.newBoolean(API_FIRST, "Generate the API from the OAI spec at server compile time (API first approach)", apiFirst));
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,"Use Optional container for optional parameters", useOptional));
cliOptions.add(CliOption.newBoolean(HATEOAS, "Use Spring HATEOAS library to allow adding HATEOAS links", hateoas));
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application using the SpringFox integration.");
supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration.");
@@ -258,6 +261,10 @@ public class SpringCodegen extends AbstractJavaCodegen
if (additionalProperties.containsKey(API_FIRST)) {
this.setApiFirst(Boolean.valueOf(additionalProperties.get(API_FIRST).toString()));
}
if (additionalProperties.containsKey(HATEOAS)) {
this.setHateoas(Boolean.valueOf(additionalProperties.get(HATEOAS).toString()));
}
typeMapping.put("file", "Resource");
importMapping.put("Resource", "org.springframework.core.io.Resource");
@@ -698,6 +705,10 @@ public class SpringCodegen extends AbstractJavaCodegen
public void setApiFirst(boolean apiFirst) {
this.apiFirst = apiFirst;
}
public void setHateoas(boolean hateoas) {
this.hateoas = hateoas;
}
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache
+ 7
- 0
  • View file @ e569f0e6


@@ -155,5 +155,12 @@
</dependency>
<!-- END Virtual Service API support -->
{{/virtualService}}
{{#hateoas}}
<!-- Spring HATEOAS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
{{/hateoas}}
</dependencies>
</project>
modules/openapi-generator/src/main/resources/JavaSpring/model.mustache
+ 5
- 0
  • View file @ e569f0e6


@@ -19,6 +19,11 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
{{#withXml}}
import javax.xml.bind.annotation.*;
{{/withXml}}
{{^parent}}
{{#hateoas}}
import org.springframework.hateoas.ResourceSupport;
{{/hateoas}}
{{/parent}}
{{#models}}
{{#model}}
modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache
+ 1
- 1
  • View file @ e569f0e6


@@ -3,7 +3,7 @@
*/{{#description}}
@ApiModel(description = "{{{description}}}"){{/description}}
{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{^parent}}{{#hateoas}}extends ResourceSupport {{/hateoas}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
{{#serializableModel}}
private static final long serialVersionUID = 1L;
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: OpenAPITools/openapi-generator!1202
Source branch: github/fork/mwoodland/master

Menu

Explore Projects Groups Snippets