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

Object is possibly undefined this.httpRequest #689

Open
sndrem opened this issue Jun 17, 2024 · 8 comments
Open

Object is possibly undefined this.httpRequest #689

sndrem opened this issue Jun 17, 2024 · 8 comments
Labels
bug 🔥 Something isn't working

Comments

@sndrem
Copy link

sndrem commented Jun 17, 2024

Description

I am trying to update the package to version 0.47.0, but when generating the client I get an error saying that Object is possibly 'undefined'.

See screenshot for the problematic generated code. I am not sure how to bypass this, if this is a bug with openapi-ts or if I can get past the error some other way?

image

OpenAPI specification (optional)

No response

Configuration

This is the command used to generate the client

openapi-ts --useOptions --name MulighetsrommetClient --input ../../mulighetsrommet-api/src/main/resources/web/openapi.yaml --output ./build"

and this is the openapi config

import { defineConfig } from "@hey-api/openapi-ts";

export default defineConfig({
  input: "../../mulighetsrommet-api/src/main/resources/web/openapi.yaml",
  output: "./build",
  client: "fetch",
  types: {
    enums: "typescript",
  },
});

System information (optional)

No response

@mrlubos
Copy link
Contributor

mrlubos commented Jun 17, 2024

Hey @sndrem, can you share your OpenAPI spec?

@sndrem
Copy link
Author

sndrem commented Jun 17, 2024

Sure,

  /api/v1/intern/avtaler/{id}:
    parameters:
      - $ref: "#/components/parameters/ID"
    get:
      tags:
        - Avtaler
      operationId: getAvtale
      responses:
        200:
          description: The specified avtale.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Avtale"
        404:
          description: "Avtalen ble ikke funnet"
          content:
            application/json:
              schema:
                type: string
    Avtale:
      type: object
      properties:
        id:
          type: string
          format: uuid
        tiltakstype:
          $ref: "#/components/schemas/EmbeddedTiltakstype"
        navn:
          type: string
        avtalenummer:
          type: string
        websaknummer:
          type: string
        lopenummer:
          type: string
        arrangor:
          $ref: "#/components/schemas/ArrangorHovedenhet"
        startDato:
          type: string
          format: date
        sluttDato:
          type: string
          format: date
        avtaletype:
          $ref: "#/components/schemas/Avtaletype"
        status:
          $ref: "#/components/schemas/AvtalestatusResponse"
        arenaAnsvarligEnhet:
          $ref: "#/components/schemas/ArenaNavEnhet"
        prisbetingelser:
          type: string
          nullable: true
        administratorer:
          type: array
          items:
            $ref: "#/components/schemas/AvtaleAdministrator"
        antallPlasser:
          type: number
          nullable: true
        kontorstruktur:
          $ref: "#/components/schemas/NavKontorStruktur"
        opphav:
          $ref: "#/components/schemas/Opphav"
        beskrivelse:
          type: string
        faneinnhold:
          $ref: "#/components/schemas/SanityFaneinnhold"
        personopplysninger:
          type: array
          items:
            $ref: "#/components/schemas/Personopplysning"
        personvernBekreftet:
          type: boolean
        nusData:
          type: object
          properties:
            versjon:
              type: string
            utdanningsnivaa:
              type: string
            utdanningskategorier:
              type: array
              items:
                type: object
                properties:
                  code:
                    type: string
                    nullable: false
                  name:
                    type: string
                    nullable: false
                required:
                  - code
                  - name
          nullable: true
        amoKategorisering:
          $ref: "#/components/schemas/AmoKategorisering"
          nullable: true
      required:
        - id
        - tiltakstype
        - navn
        - avtalenummer
        - arrangor
        - startDato
        - avtaletype
        - status
        - prisbetingelser
        - kontorstruktur
        - opphav
        - personopplysninger
        - personvernBekreftet
        - amoKategorisering

@guesant
Copy link

guesant commented Jun 26, 2024

Seems like setting services.asClass = true produces an output that don't have this issue.

But how it's supposed to work without classes? It's a work-in-progress feature? As it is a arrow function, the this param is not bindable with method.bind(providerThis) or method.call(providerThis). Seems like a breaking change.

This is the default, with services.asClass not provided or false:

image

With services.asClass set to be true:

image

@mrlubos
Copy link
Contributor

mrlubos commented Jun 26, 2024

@guesant It's the name parameter causing this which is deprecated, hence no support for making it work together

@guesant
Copy link

guesant commented Jun 26, 2024

@guesant It's the name parameter causing this which is deprecated, hence no support for making it work together

Wow, that's true. Thank you @mrlubos. Removing the name produces the following output:

image

I just didn't now, I'm gonna drop the usage of name.

Thanks.

@guesant
Copy link

guesant commented Jun 26, 2024

I'm gonna take a look at the migration guide before posting here, as it's supposed to have changes before the major version (and I love this project and the improvements its get over the days).

To anyone interested:

The changes started from v0.46.

@guesant
Copy link

guesant commented Jun 26, 2024

I'm gonna take a look at the migration guide before posting here, as it's supposed to have changes (and I love this project and the improvements it get over the days).

For anyone interested:

The changes started from v0.45.

--

dependabot just updated the dep and we didn't read the migration guide 😅

@mrlubos
Copy link
Contributor

mrlubos commented Jun 26, 2024

No worries, let me know if there's a use case for the deprecated stuff that isn't covered today. Generally minor releases pre-v1 might contain breaking changes, those would be documented in the migration guide. Thanks for using this package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants