question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] [typescript-fetch] Request Parameter Interfaces Conflict with remove-operation-id-prefix

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When an API spec contains two similarly named operations that differ only in prefix:

      operationId: tag_new_create
...
      operationId: unit_new_create

then generating the typescript-fetch client with the --remove-operation-id-prefix option will result in an error like:

apis/index.ts:2:1 - error TS2308: Module './TagApi' has already exported a member named 'NewCreateRequest'. Consider explicitly re-exporting to resolve the ambiguity.
openapi-generator version

This is in 4.0.0beta. The same error did not occur with the old 3.x typescript-fetch, though this new implementation is generally much better.

OpenAPI declaration file content or url

https://gist.github.com/bradenmacdonald/061c37b42af22832a14574e4aeaa5c59

Command line used for generation
java -jar openapi-generator-cli-4.0.0-beta.jar generate \
    --input-spec api-spec.yaml \
    --generator-name typescript-fetch \
    --output api_client \
    --config openapi-generator-config.json \
    --remove-operation-id-prefix
Steps to reproduce

Simply generate the typescript-fetch client using the sample gist and the command above, then run cd api_client; npm install; npm run build

Related issues/PRs

I couldn’t find any existing reports of this issue.

Suggest a fix

Ideally just never omit the prefixes when generating the request parameter interfaces, so that the interface is still called e.g. TagNewCreateRequest (instead of interface NewCreateRequest) regardless of the --remove-operation-id-prefix option (the main reason I use that option is for nicer method names; the names of the parameter interfaces aren’t often used directly so it’s fine if they’re more verbose).

Alternately, put each module’s interfaces into a namespace for that module, so that one must use e.g. TagApi.NewCreateRequest to get the interface after importing the overall API.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
jgilescommented, Aug 26, 2019

Updated: change the namespacing flag to prefixing flag.

Starting with release 4.1.1 (which should be out soon), you can avoid this issue by passing

--additional-properties=prefixParameterInterfaces=true

on the command line with your generate command.

Or, adding "prefixParameterInterfaces": true to myconfig.json and passing -c myconfig.json with your generate command

2reactions
Teyrascommented, Apr 4, 2019

This conflict also happens when I already have a model definition that is accidentally named {operaitionId}Request

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage - OpenAPI Generator
The batch command allows you to move all CLI arguments supported by the generate command into a YAML or JSON file. NOTE: This...
Read more >
Quickest and simplest way to convert fetch JavaScript to work ...
When you later pass the object to fetch , TypeScript thinks the value you used can be any string and you get an...
Read more >
RequestInit | typescript - v3.7.7
A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's...
Read more >
How To Generate Response Objects With Openapi Generator
Learn how to generate a Spring-based server stub from a YAML As the name suggests, the OpenAPI Generator generates code from an OpenAPI...
Read more >
Better JavaScript Fetch Functions with Currying and TypeScript
The JavaScript fetch API exposes an interface to effectively handle HTTP requests and responses. With the aid of the window scoped fetch function, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found