@@ -65,6 +65,42 @@ const validationFormatters: Record<string, (value: unknown) => ValidationFormat
6565 default : createValidationsFormatter ( 'Default' ) ,
6666} ;
6767
68+ const oasFormats = {
69+ int32 : {
70+ minimum : 0 - 2 ** 31 ,
71+ maximum : 2 ** 31 - 1 ,
72+ } ,
73+ int64 : {
74+ minimum : 0 - 2 ** 63 ,
75+ maximum : 2 ** 63 - 1 ,
76+ } ,
77+ float : {
78+ minimum : 0 - 2 ** 128 ,
79+ maximum : 2 ** 128 - 1 ,
80+ } ,
81+ double : {
82+ minimum : 0 - Number . MAX_VALUE ,
83+ maximum : Number . MAX_VALUE ,
84+ } ,
85+ byte : {
86+ pattern : '^[\\w\\d+\\/=]*$' ,
87+ } ,
88+ } ;
89+
90+ function filterOutOasFormatValidations ( format : string , values : Dictionary < unknown > ) {
91+ if ( ! ( format in oasFormats ) ) return values ;
92+
93+ const newValues = { ...values } ;
94+
95+ for ( const [ key , value ] of Object . entries ( oasFormats [ format ] ) ) {
96+ if ( value === newValues [ key ] ) {
97+ delete newValues [ key ] ;
98+ }
99+ }
100+
101+ return newValues ;
102+ }
103+
68104export const Validations : React . FunctionComponent < IValidations > = ( { validations } ) => {
69105 const numberValidations = pick ( validations , numberValidationNames ) ;
70106 const booleanValidations = omit (
@@ -172,6 +208,14 @@ export function getValidationsFromSchema(schemaNode: RegularNode) {
172208 ...( schemaNode . annotations [ 'x-example' ] ? { [ 'x-example' ] : schemaNode . annotations [ 'x-example' ] } : null ) ,
173209 }
174210 : null ) ,
175- ...schemaNode . validations ,
211+ ...getFilteredValidations ( schemaNode ) ,
176212 } ;
177213}
214+
215+ function getFilteredValidations ( schemaNode : RegularNode ) {
216+ if ( schemaNode . format !== null ) {
217+ return filterOutOasFormatValidations ( schemaNode . format , schemaNode . validations ) ;
218+ }
219+
220+ return schemaNode . validations ;
221+ }
0 commit comments