fortanix / openapi-to-effect

Generate @effect/schema definitions from an OpenAPI document
Mozilla Public License 2.0
8 stars 1 forks source link

unable to generate when ref name contains illegal characters #1

Closed joepjoosten closed 1 week ago

joepjoosten commented 1 week ago

I'm parsing the spec for opensearch (https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml) which contains schemas with names like: "cat._common:CatPitSegmentsRecord" or "_common:AcknowledgedResponseBase", which will result in incorrect typescript code because the schemaId generated is invalid.

export const _common:AcknowledgedResponseBase = S.Struct({

  /** For a successful response, this value is always true. On failure, an exception is returned instead. */
  acknowledged: S.Boolean,
}); 
export type _common:AcknowledgedResponseBase = S.Schema.Type<typeof _common:AcknowledgedResponseBase>;
export const _common:AcknowledgedResponseBaseEncoded = S.encodedSchema(_common:AcknowledgedResponseBase);
export type _common:AcknowledgedResponseBaseEncoded = S.Schema.Encoded<typeof _common:AcknowledgedResponseBase>;
mkrause commented 1 week ago

You're right, the generator was assuming that schemas have names that are valid JS identifiers. I pushed a fix that:

  1. Encodes names as valid JS identifiers
  2. Adds proper parsing for JSON pointers so that names with special characters (/ and ~) don't cause parse errors.

Also added a test for it. Published as v0.7.0. Let me know if this resolves the issue for you.

joepjoosten commented 1 week ago

I will check

joepjoosten commented 1 week ago

JS identifiers are ok now, but found a new issue #2