Skip to content

Commit

Permalink
Start on making structure
Browse files Browse the repository at this point in the history
Edit gitignore

Add some new files

I made some more progress on the structure, and I'm about to write some
tests for the functionality that ensures required fields are full.
Also write a part of a Makefile

Make Makefile work

Also rearrange things. Now I just need to actually test the methods and
I'm good.

Finish tests

Now I know my requirement checker methods work!

Make some more progress on the structure

Just work until make test runs right. Not complicated, at least.

Move forward on structural classes

I need to actually write the Schema class, make sure everything has the
right constructor, and then finish up with all the compile errors.

Start on Schema class

This could be a bit complicated

Update gitignore

Remove compile errors

I didn't get to test yet, but it compiles. That's got to be good, right?
Also take care of one TODO

Do some devops-y stuff

Improve test running. I like to worry about the sexy things.

Remove dependency on Java 8

It's amazing how much easier that makes this.

Fix some more test issues

Now they'll actually run. I changed something that made them fail
before, but it's all good now.

Revamp requirement checking

Now it throws an error instead of just printing, so you can see where
the problem is.

Working on some more tests

Some of them don't work. I just need to fix them, not a big deal, and
then keep moving. Also, make them a little more compartmentalized. Right
now, I've got almost everything in one big test function, which isn't
probably ideal. I'll get there though.

Fix problem from last commit

Replace RuntimeErrors with custom ones

Now there is a special Exception calss for Swagger validation errors.
That's probably better.

Add and rearrange some more tests

Edit gitignore

I have swap files globally ignored, but some people don't.

Move things around

I'm getting ready to add a new file that will create Swagger instances,
and I thought it shouldn't go on the same level as the other classes.

Start on SwaggerBuilder

It doesn't compile or do anything, but I'm getting there.

Write the skeleton for the SwaggerBuilder class

Format

Add license headers

Comment out SwaggerBuilder

It doesn't compile because of import issues, but I can't sort them out
because I don't know how the file will fit into the directory tree.
  • Loading branch information
ddsnowboard authored and aklish committed Jan 4, 2017
1 parent 949154d commit c96eb2d
Show file tree
Hide file tree
Showing 34 changed files with 1,393 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,7 @@ test-output/
*.iml
bin
dependency-reduced-pom.xml
*.jar
*.class
*tags
**.swp
36 changes: 36 additions & 0 deletions elide-contrib/elide-swagger/Makefile
@@ -0,0 +1,36 @@
.PHONY: all clean test tags vim
GSON="https://repo1.maven.org/maven2/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar"
JUNIT="http://search.maven.org/remotecontent?filepath=junit/junit/4.12/junit-4.12.jar"
HAMCREST="http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"
all : gson.jar bin
zsh -c "javac -cp ./src:gson.jar -d bin src/com/**/*.java"

clean :
-rm -rf bin
-rm *.jar 2>/dev/null
-rm tags

test : all hamcrest.jar junit.jar bin/test/SwaggerTest.class
java -cp .:junit.jar:hamcrest.jar:bin org.junit.runner.JUnitCore test.SwaggerTest

gson.jar :
wget -O gson.jar $(GSON)

hamcrest.jar :
wget -O hamcrest.jar $(HAMCREST)

junit.jar :
wget -O junit.jar $(JUNIT)

bin :
mkdir bin

tags :
zsh -c "ctags -R ./**/*.java(N)"

vim :
zsh -c "vim ./**/*.java"

bin/test/SwaggerTest.class : src/test/SwaggerTest.java
javac -cp hamcrest.jar:junit.jar:./src/:gson.jar src/test/SwaggerTest.java -d bin

@@ -0,0 +1,26 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

public class Contact extends SwaggerComponent {
private static final String[] REQUIRED = {};
public String name;
public String url;
public String email;
public Contact()
{
required = REQUIRED;
}
@Override
public void checkRequired() throws SwaggerValidationException
{
if(url != null && !Util.validateURL(url))
throw new SwaggerValidationException("The URL must be properly formatted");

if(email != null && !Util.validateEmail(email))
throw new SwaggerValidationException("The email address must be properly formatted");
}
}
@@ -0,0 +1,12 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

import java.util.HashMap;

public class Definitions extends HashMap<String, Schema> {

}
@@ -0,0 +1,143 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

import com.google.gson.annotations.SerializedName;

public class Enums {
public enum Location {
@SerializedName("query")
QUERY,

@SerializedName("header")
HEADER,

@SerializedName("path")
PATH,

@SerializedName("formData")
FORM_DATA,

@SerializedName("body")
BODY
};

public enum Format {
@SerializedName("csv")
CSV,

@SerializedName("SSV")
SSV,

@SerializedName("TSV")
TSV,

@SerializedName("pipes")
PIPES,

@SerializedName("multi")
MULTI
};

public enum Type {
@SerializedName("string")
STRING,

@SerializedName("number")
NUMBER,

@SerializedName("integer")
INTEGER,

@SerializedName("boolean")
BOOLEAN,

@SerializedName("array")
ARRAY,

@SerializedName("file")
FILE,
};

public enum Scheme {
@SerializedName("wss")
WSS,

@SerializedName("ws")
WS,

@SerializedName("http")
HTTP,

@SerializedName("https")
HTTPS
};

public enum DataType {
@SerializedName("integer")
INTEGER,

@SerializedName("long")
LONG,

@SerializedName("float")
FLOAT,

@SerializedName("double")
DOUBLE,

@SerializedName("string")
STRING,

@SerializedName("byte")
BYTE,

@SerializedName("binary")
BINARY,

@SerializedName("boolean")
BOOLEAN,

@SerializedName("date")
DATE,

@SerializedName("dateTime")
DATETIME,

@SerializedName("password")
PASSWORD
};

public enum SecurityType {
@SerializedName("basic")
BASIC,

@SerializedName("apiKey")
APIKEY,

@SerializedName("oauth2")
OAUTH2
};

public enum ApiKeyLocation {
@SerializedName("query")
QUERY,

@SerializedName("header")
HEADER
};

public enum Flow {
@SerializedName("implicit")
IMPLICIT,
@SerializedName("password")
PASSWORD,
@SerializedName("application")
APPLICATION,
@SerializedName("accessCode")
ACCESSCODE
}
}
@@ -0,0 +1,11 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

import java.util.HashMap;

public class Example extends HashMap<MimeType, Object> {
}
@@ -0,0 +1,16 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

public class ExternalDocumentation extends SwaggerComponent {
private static final String[] REQUIRED = {"url"};
public String description;
public String url;
public ExternalDocumentation()
{
required = REQUIRED;
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

public class Header extends SwaggerComponent {
private static final String[] REQUIRED = {"type"};
public String description;
public Enums.Type type;
public Enums.DataType format;
public Items items;
public Enums.Format collectionFormat;
public Header defaultValue;
public int maximum;
public boolean exclusiveMaximum;
public int minimum;
public boolean exclusiveMinimum;
public int maxLength;
public int minLength;
public String pattern;
public int maxItems;
public int minItems;
public boolean uniqueItems;
public Object[] enumeration;
public int multipleOf;

public Header()
{
this.required = REQUIRED;
}

@Override
public void checkRequired() throws SwaggerValidationException
{
super.checkRequired();

if(type == Enums.Type.ARRAY)
if(items == null)
throw new SwaggerValidationException("If the type is an array, then the items (ie, the thing describing what's in the array) can't be null");
}
}
@@ -0,0 +1,12 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

import java.util.HashMap;

public class Headers extends HashMap<String, Header> {

}
@@ -0,0 +1,20 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

public class Info extends SwaggerComponent {
private static final String[] REQUIRED = {"title", "version"};
public String title;
public String description;
public String termsOfService;
public Contact contact;
public License license;
public String version;
public Info()
{
this.required = REQUIRED;
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;


public class Items extends SwaggerComponent {
private static final String[] REQUIRED = {"type"};
public Enums.Type type;
public Enums.DataType format;
public Items items;
public Enums.Format collectionFormat;
public Object defaultValue;
public int maximum;
public boolean exclusiveMaximum;
public int minimum;
public boolean exclusiveMinimum;
public int maxLength;
public int minLength;
public String pattern;
public int maxItems;
public int minItems;
public boolean uniqueItems;
public Object[] enumeration;
public int multipleOf;

public Items()
{
required = REQUIRED;
}
@Override
public void checkRequired() throws SwaggerValidationException
{
super.checkRequired();

if(type == Enums.Type.ARRAY && items == null)
throw new SwaggerValidationException("If the type is an array, then the items (ie, the thing describing what's in the array) can't be null");
}
}
@@ -0,0 +1,16 @@
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.contrib.swagger.JSONObjectClasses;

public class License extends SwaggerComponent {
private static final String[] REQUIRED = {"name"};
public String name;
public String url;
public License()
{
required = REQUIRED;
}
}

0 comments on commit c96eb2d

Please sign in to comment.