Git Product home page Git Product logo

openapi-processor-spring's Introduction

openapi-processor-spring logo

openapi-processor-spring

an OpenAPI interface only & model java code generator for Spring Boot.

documentation

See here.

snapshot repository

to use snapshot versions add https://oss.sonatype.org/content/repositories/snapshots as maven repository to your build file.

openapi-processor-spring's People

Contributors

dependabot[bot] avatar hauner avatar mikrethor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openapi-processor-spring's Issues

skip endpoint

add the possibility to skip generation of an endpoint.

It would be annoying if we can't use the generatr because it does not create proper code for a single (or multiple) endpoint(s).

By telling the generatr which endpoints to skip we can still use it for all the other endpoints with correct code and create a hand written endpoint for the skipped endpoints.

move options to mapping yaml

now (#68) that we have direct access to the mapping information in SpringGeneratr move the options

  • packageName
  • beanValidation

to the mapping yaml.

That way everything that is related to the code generation is in the same place.

add additional parameters via mapping

add parameters that are not defined in the openapi to an endpoint via

map:
  paths:
    /foo:

      parameters:
        - add: request
          as: javax.servlet.http.HttpServletRequest

map json identifiers to proper java identifiers

currently the parameter & property names are used as-is to generate interfaces and models. This can lead to invalid java identifiers.

  • convert parameter names to valid java identifiers
  • convert object properties names to valid java identifiers and annotate them with @JsonProperty

funny inline type names

creating type names for inline types doesn't properly handle the /es in the path. It creates e.g. funny things like: Api/generatrRequestBody for the request body of the path /api/generatr.

use mapping to map exploded object to Map

Should be possible to use the mapping to map an query parameter object to a Map

  • @RequestParam(name="prop") Map<String, String>, the request parameter "prop" is converted into a map not needed atm.

  • @RequestParam Map<String, String>, puts all request parameters into a map

  • @RequestParam MultiValueMap<String, String>, puts all request parameters into a map, allowing multiple parameters of the same name

Example (openapi yaml snippet):

/endpoint-object:
  get:
    description: <
      should be mapped to a `Props` pojo without `@RequestParam` annotation

        /endpoint-object?prop1=foo&prop2=bar

    parameters:
      - name: props
        description: query parameter object
        in: query
        schema:
          $ref: '#/components/schemas/Props'

components:
  schemas:
    Props:
      type: object
      properties:
        prop1:
          type: string
        prop2:
          type: string

see #64

mising bean validation annotations

the check if a bean validation annotation should be added fails with "0" constraints.

  • it does check if (value) which is false if value is 0
  • it should check value != null

convert response body with content "multipart/form-data" and array schema to @RequestParam

Assuming the following open api snippet for a request body for uploading multiple files:

  requestBody:
    required: true
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            files:
              type: array
              items:
                type: string
                format: binary

the generatr should create an additional query parameter instead of a @RequestBody parameter, in this case as array

 @RequestParam(name = "files") MultipartFile[] files

handle exploded object query parameters

The following openapi query parameter

/foo:
  get:
    parameters:
      - name: props
        in: query
        explode: true
        schema:
          type: object
          properties:
            prop1:
              type: string
            prop2:
              type: string

The explode: true tells us that the object is serialized as multiple query parameters. The generatr should produce an endpoint like this:

@GetMapping(path = "/endpoint-object")
ResponseEntity<Void> getEndpointObject(GetFooProps props);
  • no @RequestParam annotation

support bean validation

support javax.validation.validation-api by

  • adding @Valid annotation to parameters
  • adding validation api annotations to model properties based on openapi constraints
openapi annotation comment
minimum @Min only if exclusiveMinimum = false (default)
maximum @Max only if exclusiveMaximum = false (default)
minLength @Size(min = .. )
maxLength @Size(max = .. )
? @NotNull default?
? @Null
pattern @Pattern

wrong DataType imports

issue:
in case a DataType is a generic type, String DataType.getImport() does not contain the imports of the generic types.

solution:
The method should change its return type Set<String> and add the generic types.

missing import of mapped target type

looks like the target type of a type mapping gets no import statement in the generate code. For example using the following mapping

map:
  paths:
    /api/generatr:
      types:
        - from: ApiGeneratrRequestBody
          to: org.springframework.web.multipart.MultipartFile

it does not generate an import for MultipartFile.

Is there no test?

convert response body with content "multipart/form-data" to @RequestParam parameters

Assuming the following open api snippet for a request body:

  requestBody:
    required: true
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            file:
              type: string
              format: binary
            other:
              type: string

the generatr should create an additional query parameter for each property of the schema object instead of a @ReqeustBody parameter, in this case

 @RequestParam(name = "file") MultipartFile file,
 @RequestParam(name = "other") String other

type mappings

  • simple types #43
    • global mapping #7
    • global parameter #16
    • global response #17
    • endpoint mapping #18
    • endpoint parameter #19
    • endpoint response #20
  • array type #41
    • global mapping
    • global parameter
    • global response
    • endpoint mapping
    • endpoint parameter
    • endpoint response
  • object type
    • global mapping
    • global parameter #37
    • global response #35
    • endpoint mapping #39
    • endpoint parameter #29
    • endpoint response #31

support requestBody:

support OpenAPI requestBody: block, annotate method parameter with @RequestBody

enum support

support enum constraint on types by generating an enum class (?)

      schema:
        type: string
        enum: [asc, desc]

@RequestParam default value should be string

generatr creates code like this:

@RequestParam(name = "page", required = false, defaultValue = 0) Integer page,

but should be

@RequestParam(name = "page", required = false, defaultValue = "0") Integer page,

missing @ResponseBody import

the generatr does not add the import for the @ResponseBody annotation when an endpoint method is using it.

Is there no test for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.