Skip to content

Commit

Permalink
fix(docs): simplified docs
Browse files Browse the repository at this point in the history
  • Loading branch information
enkot committed Sep 23, 2023
1 parent 3b069ee commit b357822
Show file tree
Hide file tree
Showing 6 changed files with 1,018 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineNuxtConfig({
})
```

That's it! You can now use My Module in your Nuxt app ✨
That's it! You can now use `nuxt-open-fetch` in your Nuxt app ✨

## Development

Expand Down
24 changes: 7 additions & 17 deletions docs/content/1.introduction/1.quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,25 @@ npm install nuxt-open-fetch -D
Then, add `nuxt-open-fetch` to the [`modules`](https://nuxt.com/docs/api/configuration/nuxt-config#modules) section of your Nuxt configuration:

```ts [nuxt.config.ts]
export default {
export default defineNuxtConfig({
modules: ['nuxt-open-fetch'],
openFetch: {
clients: {
pets: {
fetchOptions: {
baseURL: 'https://petstore3.swagger.io/api/v3'
}
},
rickAndMorty: {
fetchOptions: {
baseURL: 'https://rickandmortyapi.com/api'
}
}
}
}
}
})
```
By default `nuxt-open-fetch` will search for OpenAPI schemas in `/openapi` directory.

```
openapi/
pets/
openapi.yaml
rickAndMorty/
openapi.json
nuxt.config.ts
```

Expand All @@ -75,19 +68,16 @@ const { data, error } = await usePetsFetch('/pet/{petId}', {
}))
})
// ...
// or
const { data, error } = await useRickAndMortyFetch('/character', {
query: computed(() => ({
page: page.value
}))
const data = await $petsFetch('/pet/{petId}', {
params: {
petId
}
})
</script>
```
Also generated:
- `$petsFetch`, `$rickAndMortyFetch` utils
- `useLazyPetsFetch`, `useLazyRickAndMortyFetch` composables

`nuxt-open-fetch` infers types from the URL. Prefer static string values over dynamic runtime values, e.g.:
::alert{type="success"}
Expand Down
12 changes: 12 additions & 0 deletions playground/pets/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default defineNuxtConfig({
modules: ['../src/module'],
openFetch: {
clients: {
pets: {
fetchOptions: {
baseURL: 'https://petstore3.swagger.io/api/v3'
}
}
}
}
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,193 @@
openapi: 3.0.2
info:
title: Swagger Petstore - OpenAPI 3.0
...
description: "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.\
\ You can find out more about\nSwagger at [http://swagger.io](http://swagger.io).\
\ In the third iteration of the pet store, we've switched to the design first\
\ approach!\nYou can now help us improve the API whether it's by making changes\
\ to the definition itself or to the code.\nThat way, with time, we can improve\
\ the API in general, and expose some of the new features in OAS3.\n\nSome useful\
\ links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n\
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)"
termsOfService: http://swagger.io/terms/
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.17
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: /api/v3
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: http://swagger.io
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: http://swagger.io
- name: user
description: Operations about user
paths:
/pet:
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
requestBody:
description: Update an existent pet in the store
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
required: true
responses:
"200":
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
"400":
description: Invalid ID supplied
"404":
description: Pet not found
"405":
description: Validation exception
security:
- petstore_auth:
- write:pets
- read:pets
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
requestBody:
description: Create a new pet in the store
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
required: true
responses:
"200":
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
"405":
description: Invalid input
security:
- petstore_auth:
- write:pets
- read:pets
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: false
explode: true
schema:
type: string
default: available
enum:
- available
- pending
- sold
responses:
"200":
description: successful operation
content:
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
"400":
description: Invalid status value
security:
- petstore_auth:
- write:pets
- read:pets
/pet/findByTags:
get:
tags:
- pet
summary: Finds Pets by tags
description: "Multiple tags can be provided with comma separated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: findPetsByTags
parameters:
- name: tags
in: query
description: Tags to filter by
required: false
explode: true
schema:
type: array
items:
type: string
responses:
"200":
description: successful operation
content:
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
"400":
description: Invalid tag value
security:
- petstore_auth:
- write:pets
- read:pets
/pet/{petId}:
get:
tags:
Expand Down
11 changes: 10 additions & 1 deletion test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ import NuxtOpenFetch from '../../../src/module'
export default defineNuxtConfig({
modules: [
NuxtOpenFetch
]
],
openFetch: {
clients: {
pets: {
fetchOptions: {
baseURL: 'https://example.com/pets'
}
}
}
}
})
Loading

0 comments on commit b357822

Please sign in to comment.