Skip to content
GitLab
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
  • !2617

[TypeScript-Fetch] Generate oneOf schemas as type unions

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/fantavlik/ts-fetch-oneof-type-unions into master Apr 06, 2019
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: fantavlik

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;
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/fantavlik/ts-fetch-oneof-type-unions