Giter Club home page Giter Club logo

swagger-tools's People

Contributors

agliznetsov avatar netonlive avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

dvdeurse

swagger-tools's Issues

Default values for enums

The following spec shows the use of a default value for the enumProp field:

EnumExample:
  type: string
  enum:
    - One
    - Two

ObjectExample:
  type: object
  properties:
    enumProp:
      $ref: '#/components/schemas/EnumExample'
      default: 'One'

When generating the model classes, the 'default' value is not taken into account. It does work for simple datatypes though, but not for enumeration types that are referenced.

Inherited classes should have callSuper=true in toString lombok annotation

Hi Andrey,

How are you?
We still use this plugin to generate our rest api classes. :)
And so when the inherited class is generated the lombok ToString annotation is added without a callSuper.
And so the properties of the super class are not added in the string representation.

f.e.

`
package com.evs.phoenix.transform.payloads;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.lang.Boolean;
import java.lang.String;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@tostring
@EqualsAndHashCode
public class FileLocation extends Location {
@JsonProperty("_type")
private final String type = "FileLocation";

@JsonProperty("present")
private Boolean present;

public String getType() {
    return type;
}

public Boolean isPresent() {
    return present;
}

public void setPresent(Boolean present) {
    this.present = present;
}

}
`

Polymorphic list items in request body

Consider the following spec:

paths:
  /animals:
    post:
      operationId: createAnimals
      requestBody:
        description: animal
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Animal'
        required: true

components:
    Animal:
      type: object
      properties:
        name:
          type: string
      discriminator:
        propertyName: '@type'

    Dog:
      allOf:
        - $ref: '#/components/schemas/Animal'

    Cat:
      allOf:
        - $ref: '#/components/schemas/Animal'

When you generate a client for this spec, it will fail because the generated code is not providing the type information to the client library (e.g. resttemplate, webclient). Jackson needs this information as it cannot know the type from an incoming List of objects.

The invokeApi method (in this example for resttemplate) should be something similar to (note the additional requestBodyTypeRef param):

    protected <T, U> ResponseEntity<T> invokeAPI(String path, String method, Map<String, String> urlVariables, MultiValueMap<String, String> queryParams, Object body, ParameterizedTypeReference<U> requestBodyTypeRef, ParameterizedTypeReference<T> returnType) {
        URI baseUrl = restTemplate.getUriTemplateHandler().expand(basePath);
        URI uri = UriComponentsBuilder
                .fromUri(baseUrl)
                .path(path)
                .queryParams(queryParams)
                .buildAndExpand(urlVariables)
                .toUri();
        RequestEntity.BodyBuilder requestBuilder = RequestEntity.method(HttpMethod.resolve(method), uri);
        customizeRequest(requestBuilder);
        RequestEntity<Object> requestEntity = requestBuilder.body(body, requestBodyTypeRef.getType());
        return restTemplate.exchange(requestEntity, returnType);
    }

Use of Flux in Webclient dialect

Consider the following spec, where we declare a GET that returns a list of items:

/list:
  get:
    tags:
      - Example
    operationId: getExampleList
    responses:
      200:
        description: OK
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Example'

When generating a client for this method, using the WebClient dialect, it results in the following code fragment:

public Mono<List<Example>> getExampleList() {
    ParameterizedTypeReference<List<Example>> typeRef = new ParameterizedTypeReference<List<Example>>(){};
    return invokeAPI("/list", "GET", createUrlVariables(), createQueryParameters(), null).bodyToMono(typeRef);
}

While I would expect the following:

public Flux<Example> getExampleList() {
    return invokeAPI("/list", "GET", createUrlVariables(), createQueryParameters(), null).bodyToFlux(Example.class);
}

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.