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

[BUG][typescript] Cannot read properties of undefined (reading 'normalizeMediaType') #20201

Closed
5 of 6 tasks
bbortt opened this issue Nov 28, 2024 · 0 comments · Fixed by #20202
Closed
5 of 6 tasks

[BUG][typescript] Cannot read properties of undefined (reading 'normalizeMediaType') #20201

bbortt opened this issue Nov 28, 2024 · 0 comments · Fixed by #20202

Comments

@bbortt
Copy link
Contributor

bbortt commented Nov 28, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

using TypeScript generated APIs I run into:

Cannot read properties of undefined (reading 'normalizeMediaType')
TypeError: Cannot read properties of undefined (reading 'normalizeMediaType')
    at getPreferredMediaType ([...]\models\ObjectSerializer.ts:269:54)

when looking at the code, the problem seems pretty obvious. as far as I am concerned, this does not exist in a static method. that is the point of being static, isn't it? having no reference to an object.

openapi-generator version

7.10.0 of org.openapitools:openapi-generator-maven-plugin. using the typescript generator.

OpenAPI declaration file content or url

not relevant imo. can be reproduced using petstore API.

Generation Details

in the build section of pom.xml the following is contained.

<plugin>
                        <groupId>org.openapitools</groupId>
                        <artifactId>openapi-generator-maven-plugin</artifactId>
                        <configuration>
                            <configOptions>
                                <oas3>true</oas3>
                                <useTags>true</useTags>
                            </configOptions>
                            <generatorName>typescript</generatorName>
                            <output>${generator.output.dir}</output>
                        </configuration>
                        <executions>
                            <execution>
                                <id>generate-registration-resource</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <inputSpec>${maven.multiModuleProjectDirectory}/specs/${api.registration-controller.v2.file}</inputSpec>
                                    <output>${generator.output.dir}/registration</output>
                                </configuration>
                            </execution>
Steps to reproduce

if really required I can create a reproducer. but the bug is pretty logical imo.

I have applied the proposed fix locally, recompiled the library (without regenerating the API) and everything went just fine.

Related issues/PRs
Suggest a fix

update the ObjectSerializer.ts to this:

        const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType);

instead of

        const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
@bbortt bbortt changed the title [BUG] Cannot read properties of undefined (reading 'normalizeMediaType') [BUG][typescript] Cannot read properties of undefined (reading 'normalizeMediaType') Nov 28, 2024
bbortt added a commit to bbortt/openapi-generator that referenced this issue Nov 28, 2024
…cript object serializer

accessing `normalizeMediaType` should be done static in `ObjectSerializer`, as described
in OpenAPITools#20201.

fix applies only to the `typescript` generator.
macjohnny pushed a commit that referenced this issue Nov 28, 2024
… serializer (#20202)

accessing `normalizeMediaType` should be done static in `ObjectSerializer`, as described
in #20201.

fix applies only to the `typescript` generator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant