Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript-Fetch] Generate oneOf schemas as type unions #2617

Merged
merged 2 commits into from
Apr 10, 2019

Conversation

fantavlik
Copy link
Contributor

@fantavlik fantavlik commented Apr 6, 2019

PR checklist

  • [ x ] Read the contribution guidelines.
  • [ x ] 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, ./bin/openapi3/{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\.

The petsore.yaml for openapi3 doesn't include oneOf so there are no updates. See example output below.

  • [ x ] Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • [ x ] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • Generate type unions for schemas represented with oneOf format

Sample input:

openapi: 3.0.0
info:
  description: My API Template
  title: Fake Service
  version: 0.0.1
servers:
  - http://fake.com
paths:
  /getme:
    get:
      tags:
      - v1
      operationId: getMe
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyOneOf'
components:
  schemas:
    MyOneOf:
      oneOf:
        - $ref: '#/components/schemas/Foo'
        - $ref: '#/components/schemas/Bar'
        - $ref: '#/components/schemas/Baz'
    Foo:
      type: object
      properties:
        kind:
          type: string
        fooProp:
          type: integer
    Bar:
      type: object
      properties:
        kind:
          type: string
        barProp:
          type: string
    Baz:
      type: object
      properties:
        kind:
          type: string
        bazProp:
          type: string

Sample output MyOneOf.ts:

// tslint:disable
/**
 * Fake Service
 * My API Template
 *
 * OpenAPI spec version: 0.0.1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

import {
    Bar,
    Baz,
    Foo,
} from './';

/**
 * @type MyOneOf
 * @export
 */
export type MyOneOf = Bar | Baz | Foo;

@fantavlik
Copy link
Contributor Author

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

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

LGTM

@wing328
Copy link
Member

wing328 commented Apr 10, 2019

The CircleCI failure is not related to this PR

@wing328 wing328 merged commit 3036d8f into OpenAPITools:master Apr 10, 2019
@wing328 wing328 added this to the 4.0.0 milestone Apr 10, 2019
jimschubert added a commit that referenced this pull request Apr 13, 2019
* master: (47 commits)
  [Slim] Fix AbstractAuthenticator constructor TypeError (#2641)
  Fix issue 1340 - StaticHtmlGenerator to allow snake_case property names (#2612)
  Test Gradle plugin in Appveyor CI (#2651)
  Add Camptocamp to company list (#2652)
  Use percent encoding for path parameters (#2649)
  Unescape HTML characters in JS docstring (#2636)
  [ONLINE] Minor links fix (#2644)
  better handling of undefined inner property in array (#2635)
  Fix regexp error on php-slim (#2604)
  [TypeScript-Fetch] Generate oneOf schemas as type unions (#2617)
  Add Namsor as the sponsor (#2639)
  fix classname in website (#2638)
  Code review fixes (#2633)
  Move Ruby module/gem to codegen constant (#2621)
  Add sponsor section to the website (#2634)
  [Spring] Spotbugs static class and default encoding (#2609)
  Add @Zomzog (2019/04) to Java, Kotlin tech comm (#2630)
  [maven] remove validateSpec (#2614)
  Clean up the license field in various templates to ensure it's unlicense by default. (#2627)
  Fix NPE when server url is null (#2628)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants