chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!

MIT License

Downloads
10.1K
Stars
280
Committers
21

Bot releases are visible (Hide)

chanfana - v2.0.3 Latest Release

Published by G4brym about 2 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/chanfana/compare/v2.0.2...v2.0.3

chanfana - v2.0.2

Published by G4brym 4 months ago

Library Revamp

  • Rename library from itty-router-openapi to chanfana
  • Refactor everything to separate routing from openapi logic
  • Added support for Hono

Breaking Changes:

  • removed OpenAPIRouter() method
  • removed aiPlugin option
  • removed skipValidation option (see new validation method bellow)
  • itty-router is no longer a dependency and users must manually add it to their project
  • validated data is no longer send in the last argument of the handler function (see new validation method bellow)
  • Endpoint's schema is no longer a static variable
  • Endpoint's schema.parameters was renamed to schema.request to follow zod-to-openapi structure
  • Endpoint Path parameters are now called params to match the validated Data object name
  • Endpoint's schema.requestBody was renamed to schema.request.body to follow zod-to-openapi structure
  • Validation no longer occurs before the endpoint's handle function is called, developers must manually call the getValidatedData to execute the data validation step
    • Tip: you can wrap this function call with try {} catch (e) {} to handle input errors, otherwise this library will return the errors in a Json response with http 400

Additions:

  • new await this.getValidatedData<typeof this.schema>() method to retrieve all validated data, when sending <typeof this.schema> in the generic the returned value will have full typescript inference based on the schema
  • automatically coerce all headers, query and params inputs based on specified zod type
  • new fromIttyRouter() instantiate method
  • new fromHono() instantiate method

Migration Guide: https://chanfana.pages.dev/user-guide/migrating-from-itty-router-openapi/
Full Changelog: https://github.com/cloudflare/chanfana/compare/v1.1.1...v2.0.2

chanfana - v1.1.1

Published by G4brym 6 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.1.0...v1.1.1

chanfana - v1.1.0

Published by G4brym 7 months ago

What's Changed

Now you can get full type hint and type check on the data argument of every endpoint, learn more here!

export class TaskFetch extends OpenAPIRoute {
  static schema = {
    parameters: {
      taskSlug: Path(Str, {
        description: 'Task slug',
      }),
    },
  }

  async handle(request: Request, env: any, context: any, data: DataOf<typeof TaskFetch.schema>) {
    // full type hint for query, path, header, and request body parameters!
    data.params.taskSlug
    
    // ...
  }
}

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.14...v1.1.0

chanfana - v1.0.14

Published by G4brym 7 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.13...v1.0.14

chanfana - v1.0.13

Published by G4brym 7 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/1.0.13...v1.0.13

chanfana - 1.0.13

Published by G4brym 8 months ago

chanfana - v1.0.12

Published by G4brym 8 months ago

chanfana - v1.0.11

Published by G4brym 8 months ago

chanfana - v1.0.10

Published by G4brym 9 months ago

What's Changed

  • Fix all parameters not being detected in non openapi routes

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.9...v1.0.10

chanfana - v1.0.9

Published by G4brym 9 months ago

What's Changed

  • Add option to define custom base router
  • Fix path parameters not working when using nested routers

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.8...v1.0.9

chanfana - v1.0.8

Published by G4brym 9 months ago

chanfana - v1.0.7

Published by G4brym 9 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.6...v1.0.7

chanfana - v1.0.6

Published by G4brym 10 months ago

chanfana - v1.0.5

Published by G4brym 11 months ago

What's Changed

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.4...v1.0.5

chanfana - v1.0.4

Published by G4brym 11 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.3...v1.0.4

chanfana - v1.0.3

Published by G4brym about 1 year ago

What's Changed

  • Fix error on mal formatted json request body

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.2...v1.0.3

chanfana - v1.0.2

Published by G4brym about 1 year ago

chanfana - v1.0.1

Published by G4brym about 1 year ago

What's Changed

  • Improve datetime error messages
  • Fix special characters encoding in query string

Full Changelog: https://github.com/cloudflare/itty-router-openapi/compare/v1.0.0...v1.0.1

chanfana - v1.0.0

Published by G4brym about 1 year ago

What's Changed

Upgrading from an older version?

Migration guide to 1.0.0 available here!

Package Rankings
Top 34.33% on Npmjs.org
Related Projects