Q42 / openapi-typescript-validator

Generate typescript with ajv validation based on openapi schemas
26 stars 14 forks source link

case confusion in the generated output. #13

Open dwjohnston opened 2 years ago

dwjohnston commented 2 years ago

I have a repro for this here: https://github.com/dwjohnston/open-api-play/tree/91bf3bd7e1c980c197890f9cac70d49444956213

Instructions:

cd api-ts
yarn
yarn generate 

I have a sample openapi spec that I've just got from the offical website. https://oai.github.io/Documentation/examples/tictactoe.yaml

I generate the code as per your instructions.

The issue is that:

In models.ts - the types are Pascal cased: (I agree with this convention btw)

/**
 * A text message describing an error
 */
export type ErrorMessage = string;
export type Coordinate = number;
/**
 * Possible values for a board square. `.` means empty square.
 */
export type Mark = "." | "X" | "O";
export type Board = [
  [Mark, Mark, Mark],
  [Mark, Mark, Mark],
  [Mark, Mark, Mark]
];

However the attempt at imports of these models are lowercased:

/* eslint-disable */
import {
  errorMessage,
  coordinate,
  mark,
  board,
  winner,
  status,
} from "./models";

I imagine this is because in the original spec the models are all defined lower case.

As a workaround I could define those components in Pascal case in the original spec. But this does seem like a bug.