forked from loafle/openapi-generator-original
		
	fix(avro-schema): fix NPE for null enum values (#19771)
				
					
				
			This commit is contained in:
		
							parent
							
								
									817da39124
								
							
						
					
					
						commit
						cfe6520283
					
				@ -6648,7 +6648,7 @@ public class DefaultCodegen implements CodegenConfig {
 | 
			
		||||
        for (Object value : values) {
 | 
			
		||||
            if (value == null) {
 | 
			
		||||
                // raw null values in enums are unions for nullable
 | 
			
		||||
                // atttributes, not actual enum values, so we remove them here
 | 
			
		||||
                // attributes, not actual enum values, so we remove them here
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            Map<String, Object> enumVar = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
@ -199,7 +199,10 @@ public class AvroSchemaCodegen extends DefaultCodegen implements CodegenConfig {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
 | 
			
		||||
        List<Object> sanitizedValues = values.stream().map(Object::toString).map(this::sanitizeEnumValue)
 | 
			
		||||
        List<Object> sanitizedValues = values.stream()
 | 
			
		||||
            .filter(x -> x != null)
 | 
			
		||||
            .map(Object::toString)
 | 
			
		||||
            .map(this::sanitizeEnumValue)
 | 
			
		||||
            .collect(Collectors.toList());
 | 
			
		||||
        removeEnumValueCollisions(sanitizedValues);
 | 
			
		||||
        return super.buildEnumVars(sanitizedValues, dataType);
 | 
			
		||||
 | 
			
		||||
@ -28,3 +28,15 @@ components:
 | 
			
		||||
            - 'coll-ision'
 | 
			
		||||
            - 'coll_ision'
 | 
			
		||||
          type: 'string'
 | 
			
		||||
        another:
 | 
			
		||||
          enum:
 | 
			
		||||
            - 'x'
 | 
			
		||||
            - 'y'
 | 
			
		||||
            - null
 | 
			
		||||
          type: 'string'
 | 
			
		||||
        equivalent:
 | 
			
		||||
          enum:
 | 
			
		||||
            - 'x'
 | 
			
		||||
            - 'y'
 | 
			
		||||
          type: 'string'
 | 
			
		||||
          nullable: true
 | 
			
		||||
@ -20,6 +20,32 @@
 | 
			
		||||
      }],
 | 
			
		||||
      "doc": "",
 | 
			
		||||
      "default": null
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "name": "another",
 | 
			
		||||
      "type": ["null", {
 | 
			
		||||
        "type": "enum",
 | 
			
		||||
        "name": "Sample_another",
 | 
			
		||||
        "symbols": [
 | 
			
		||||
          "x",
 | 
			
		||||
          "y"
 | 
			
		||||
        ]
 | 
			
		||||
      }],
 | 
			
		||||
      "doc": "",
 | 
			
		||||
      "default": null
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "name": "equivalent",
 | 
			
		||||
      "type": ["null", {
 | 
			
		||||
        "type": "enum",
 | 
			
		||||
        "name": "Sample_equivalent",
 | 
			
		||||
        "symbols": [
 | 
			
		||||
          "x",
 | 
			
		||||
          "y"
 | 
			
		||||
        ]
 | 
			
		||||
      }],
 | 
			
		||||
      "doc": "",
 | 
			
		||||
      "default": null
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user