LuvDaSun / SkiffaGenerator

ISC License
3 stars 2 forks source link

Default content-types #72

Closed elmerbulthuis closed 4 months ago

elmerbulthuis commented 6 months ago

Default content types will make using the api a bit more friendly. Instead of

  const result = await api.findCertificate(
    {
      parameters: { certificateHandle: handle, issuedAt },
      contentType: null,
    },
  );

we will be able to do

  const result = await api.findCertificate(
    {
      parameters: { certificateHandle: handle, issuedAt },
    },
  );

or instead of

export const listCountries: api.ListCountriesOperationHandler<
  application.Authentication
> = async (incomingRequest) => {

  // ... bla

  return {
    status: 200,
    contentType: 'application/json',
    entity: () => responseEntity,
  }
}

we can do

export const listCountries: api.ListCountriesOperationHandler<
  application.Authentication
> = async (incomingRequest) => {

  // ... bla

  return {
    status: 200,
    entity: () => responseEntity,
  }
}

We will first need to specify request and response types when generating the api. We call those request and response types the enabled request and response types. Content types that are not in the list will not be generated.

Then when the content type is omitted the first content type in the enabled request or response types that is also in the request or response will be used as a default.