@platformatic/sql-openapi 3.40.0 → 3.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -16,6 +16,10 @@ export interface SQLOpenApiPluginOptions extends Partial<OpenAPIV3.Document> {
16
16
  [fieldName: string]: boolean
17
17
  } | boolean
18
18
  },
19
+ /**
20
+ * Set true to disable all reverse relationship and FK-navigation routes.
21
+ */
22
+ ignoreAllReverseRoutes?: boolean,
19
23
  }
20
24
 
21
25
  declare const plugin: FastifyPluginAsync<SQLOpenApiPluginOptions>
@@ -24,7 +28,7 @@ export default plugin
24
28
  /**
25
29
  * All the errors thrown by the plugin.
26
30
  */
27
- export module errors {
31
+ export namespace errors {
28
32
  export const UnableToCreateTheRouteForTheReverseRelationshipError: () => FastifyError
29
33
  export const UnableToCreateTheRouteForThePKColRelationshipError: () => FastifyError
30
34
  export const UnableToParseCursorStrError: () => FastifyError
package/index.js CHANGED
@@ -38,6 +38,7 @@ async function setupOpenAPI (app, opts) {
38
38
  const ignore = opts.ignore || []
39
39
  const include = opts.include || []
40
40
  const ignoreRoutes = opts.ignoreRoutes || []
41
+ const ignoreAllReverseRoutes = opts.ignoreAllReverseRoutes || false
41
42
  const paths = opts.paths || {}
42
43
 
43
44
  const { default: scalarTheme } = await import('@platformatic/scalar-theme')
@@ -140,7 +141,8 @@ async function setupOpenAPI (app, opts) {
140
141
  entity,
141
142
  prefix: localPrefix,
142
143
  ignore: ignore[entity.singularName] || {},
143
- ignoreRoutes
144
+ ignoreRoutes,
145
+ ignoreAllReverseRoutes
144
146
  })
145
147
  } else {
146
148
  // TODO support ignore
@@ -148,7 +150,8 @@ async function setupOpenAPI (app, opts) {
148
150
  entity,
149
151
  prefix: localPrefix,
150
152
  ignore,
151
- ignoreRoutes
153
+ ignoreRoutes,
154
+ ignoreAllReverseRoutes
152
155
  })
153
156
  }
154
157
  }
@@ -46,6 +46,7 @@ export async function entityPlugin (app, opts) {
46
46
  const entity = opts.entity
47
47
  const ignore = opts.ignore
48
48
  const ignoreRoutes = opts.ignoreRoutes
49
+ const ignoreAllReverseRoutes = opts.ignoreAllReverseRoutes || false
49
50
 
50
51
  const entitySchema = {
51
52
  $ref: entity.name + '#'
@@ -173,7 +174,7 @@ export async function entityPlugin (app, opts) {
173
174
  return ignoreRoute.path === reverseOpenapiPath && ignoreRoute.method === 'GET'
174
175
  })
175
176
 
176
- if (!ignoredReversedGETRoute) {
177
+ if (!ignoredReversedGETRoute && !ignoreAllReverseRoutes) {
177
178
  try {
178
179
  app.get(
179
180
  `/:${camelcase(primaryKey)}/${routePathName}`,
@@ -300,7 +301,7 @@ export async function entityPlugin (app, opts) {
300
301
  return ignoreRoute.path === targetOpenapiPath && ignoreRoute.method === 'GET'
301
302
  })
302
303
 
303
- if (!ignoredReversedGETRoute) {
304
+ if (!ignoredReversedGETRoute && !ignoreAllReverseRoutes) {
304
305
  try {
305
306
  app.get(
306
307
  `/:${camelcase(primaryKey)}/${targetRelation}`,
package/lib/errors.js CHANGED
@@ -25,3 +25,8 @@ export const PrimaryKeyNotIncludedInOrderByInCursorPaginationError = createError
25
25
  'At least one primary key must be included in orderBy clause in case of cursor pagination',
26
26
  400
27
27
  )
28
+ export const UnknownFieldError = createError(
29
+ `${ERROR_PREFIX}_UNKNOWN_FIELD`,
30
+ 'Unknown field "%s" in where.or',
31
+ 400
32
+ )
package/lib/shared.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { mapSQLTypeToOpenAPIType } from '@platformatic/sql-json-schema-mapper'
2
2
  import { buildCursorUtils } from './cursor.js'
3
+ import * as errors from './errors.js'
3
4
 
4
5
  export function generateArgs (entity, ignore) {
5
6
  const sortedEntityFields = Object.keys(entity.fields).sort()
@@ -149,6 +150,9 @@ export function rootEntityRoutes (
149
150
  .map(v => v.split('='))
150
151
  .reduce((acc, [k, v]) => {
151
152
  const [field, modifier] = k.split('.')
153
+ if (!entity.camelCasedFields[field]) {
154
+ throw new errors.UnknownFieldError(field)
155
+ }
152
156
  if (modifier === 'in' || modifier === 'nin') {
153
157
  // TODO handle escaping of ,
154
158
  v = v.split(',')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-openapi",
3
- "version": "3.40.0",
3
+ "version": "3.42.0",
4
4
  "description": "Map a SQL database to OpenAPI, for Fastify",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "typescript": "^5.5.4",
27
27
  "why-is-node-running": "^2.2.2",
28
28
  "yaml": "^2.4.1",
29
- "@platformatic/sql-mapper": "3.40.0"
29
+ "@platformatic/sql-mapper": "3.42.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "@fastify/deepmerge": "^2.0.0",
@@ -36,9 +36,9 @@
36
36
  "camelcase": "^6.3.0",
37
37
  "fastify-plugin": "^5.0.0",
38
38
  "inflected": "^2.1.0",
39
- "@platformatic/foundation": "3.40.0",
40
- "@platformatic/scalar-theme": "3.40.0",
41
- "@platformatic/sql-json-schema-mapper": "3.40.0"
39
+ "@platformatic/foundation": "3.42.0",
40
+ "@platformatic/scalar-theme": "3.42.0",
41
+ "@platformatic/sql-json-schema-mapper": "3.42.0"
42
42
  },
43
43
  "tsd": {
44
44
  "directory": "test/types"