swagger-codegen-ts icon indicating copy to clipboard operation
swagger-codegen-ts copied to clipboard

readOnly writeOnly support

Open scink opened this issue 6 years ago • 3 comments

scink avatar Jan 10 '19 15:01 scink

  • check how is it implemented in swagger-codegen
  • see how can we implement it leveraging TS type-system (two different types, field modifiers, etc.)
  • looks like we're able to track the source of type resolution (body params type, response type), so it's possible to generate different types (ones with writeOnly fields for requests, ones for readOnly fields for responses), need to investigate

raveclassic avatar Jan 10 '19 15:01 raveclassic

@raveclassic, what do you think about this? that will allow us not to break existing types (that don't have readonly or writeonly fields). at the same time we can avoid checking if type has readonly or writeonly fields.

export type TypeBase = {
    ...not readOnly and not writeOnly types
};

type WriteOnly = {
    ...writeOnly types
};

type ReadOnly = {
    ...readonly types
};

export type TypeRead = TypeBase & TypeRead;
export type TypeWrite = TypeBase & TypeWrite;
export type Type = TypeRead | TypeWrite;

scink avatar Jan 11 '19 08:01 scink

removing from milestone as it might require a lot of work when there's a simple and maintainable workaround available - just to split models by hand and use different references across the spec

raveclassic avatar Nov 06 '19 11:11 raveclassic